I need an original 2d game code in cocos2d python, I have to modified it and use
ID: 3784142 • Letter: I
Question
I need an original 2d game code in cocos2d python, I have to modified it and use it, could any one help me with steps to Develop any original 2D game using Cocos2D and available free art assets? #Game_Development
Project may be completed using Linux, Windows, or OS X. If you use OS X, you may use Spritekit instead of Cocos2D. Project must be implemented in Python and use Cocos2D. (or with Objective-Cor Swift with SpriteKit Project must be an original game. Project may use any online assets with licenses that permit academic use. Turn in licenses (text files or screen shots) for each third party asset used (Clearly identify which licenses apply to each asset). See sample Cocosoids and Whakaduke in the Resources area of this site. Grade Sheet: 2 points for any original python program that uses a Cocos2D or SpriteKit game loop, displays one or more sprites, and executes without error. 2 points for any original python program that uses Cocos2D or SpriteKit to accept user input from keyboard or mouse. 2 Points for documentation explaining how to play the game including valid inputs from users. 2 Points for object oriented design using two or more classes to encapsulate game logic. 2 Points for creativity.Explanation / Answer
Designing 2d game using cross 2d in pyhon involves the below steps...
1) Install cocos2d
pip install cocos2d --process-dependency-links
setup.install
2)
importing the required dependencies of the project using "import" statement in python
Now we need to initialize the director and have to create scene . These can be done by using the below commands>>
director.initialize( width= value, height=value,do_not_scale=True, resizable=True )
player_layer =layer.Layer()
And we will add sprites and remaining objects to their corresponding layers
3)
if anything is to be done with sprites based on keyboard input. we must include
keyboard= key. KeyStateHandler()
director.window.push_handlers(keyboard)
Basic movement game in 2d is provided below
import cocos
from cocos import actions, layer, sprite, scene
from cocos.director import director
# Player class
class Me(actions.Move):
# step() is called every frame.
# dt is the number of seconds elapsed since the last call.
def step(self, dt):
super(Me, self).step(dt) # Run step function on the parent class.
# Determine velocity based on keyboard inputs.
velocity_x = 100 * (keyboard[key.RIGHT] - keyboard[key.LEFT])
velocity_y = 100 * (keyboard[key.UP] - keyboard[key.DOWN])
# Set the object's velocity.
self.target.velocity = (velocity_x, velocity_y)
# Main class
def main():
global keyboard # Declare this as global so it can be accessed within class methods.
# Initialize the window.
director.init(width=500, height=300, do_not_scale=True, resizable=True)
# Create a layer and add a sprite to it.
player_layer = layer.Layer()
me = sprite.Sprite('human-female.png')
player_layer.add(me)
# Set initial position and velocity.
me.position = (100, 100)
me.velocity = (0, 0)
# Set the sprite's movement class.
me.do(Me())
# Create a scene and set its initial layer.
main_scene = scene.Scene(player_layer)
# Attach a KeyStateHandler to the keyboard object.
keyboard = key.KeyStateHandler()
director.window.push_handlers(keyboard)
# Play the scene in the window.
director.run(main_scene)
if __name__ == '__main__':
main()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.