I need any original 2D game, game that written in python cocos2d. I have Xcode,p
ID: 3784413 • Letter: I
Question
I need any original 2D game, game that written in python cocos2d. I have Xcode,pip, and cocos2d already installed in my mac PC.
Please give me a file that already work when I use terminal to use it.
PLEASE NOTE: I need a game in ZIP file with all .py files and sprites pictures.
this is the criteria for that game:
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
import pyglet
from pyglet.window import key
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.