Created
March 17, 2011 16:27
-
-
Save runekaagaard/874618 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import os | |
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) | |
import math | |
import pyglet | |
from pyglet import image, font | |
from pyglet.gl import * | |
from pyglet.window import key, Window | |
import cocos | |
from cocos.director import director | |
from cocos.actions import * | |
from cocos.director import director | |
from cocos.layer import Layer | |
from cocos.scene import Scene | |
from cocos.sprite import Sprite | |
WIDTH = 1024 | |
HEIGHT = 768 | |
class DataTheGame(cocos.layer.Layer): | |
is_event_handler = True | |
dx = 0 | |
dy = 0 | |
keys = set() | |
def __init__(self, director): | |
self.director = director | |
super(DataTheGame, self ).__init__() | |
self.add_plane() | |
self.schedule_interval(self.update, 0.02) | |
def update(self, dt): | |
if key.LEFT in self.keys and not key.RIGHT in self.keys: | |
self.plane.do(Rotate(-8, 0)) | |
elif key.RIGHT in self.keys: | |
self.plane.do(Rotate(8, 0)) | |
if key.SPACE in self.keys: | |
rot = math.radians(self.plane.rotation + 270) | |
self.dx += math.cos(rot) / 200 | |
self.dy += -math.sin(rot) / 200 | |
else: | |
self.dx *= 0.99 | |
self.dy *= 0.99 | |
self.dy -= 0.001 | |
self.plane.do(MoveBy((self.dx * 40, self.dy * 40), dt)) | |
def add_plane(self): | |
self.plane = Sprite(pyglet.resource.image('plane.png')) | |
self.plane.position = WIDTH/2, HEIGHT/2 | |
self.add(self.plane) | |
def on_key_press (self, key, modifiers): self.keys.add(key) | |
def on_key_release (self, key, modifiers): self.keys.remove(key) | |
if __name__ == "__main__": | |
director.init(width=WIDTH, height=HEIGHT, fullscreen=True) | |
director.run(cocos.scene.Scene(DataTheGame(director))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment