def move(self): self._x -= self._speed if self._x + self._w < 0: self._x += self._w def collide(self, other): pass def position(self): return self._x, self._y, self._w, self._h def symbol(self): return 0, self._ys, self._w, self._h arena = Arena((480, 360)) back = Background(arena, 120, 128, 256, 2) sprites = g2d.load_image("moon-patrol.png") bg = g2d.load_image("moon-patrol-bg.png") def tick(): arena.move_all() # Game logic g2d.clear_canvas() for a in arena.actors(): if isinstance(a, Background): ax, ay, aw, ah = a.position() g2d.draw_image_clip(bg, a.symbol(), (ax, ay, aw, ah)) g2d.draw_image_clip(bg, a.symbol(), (ax + aw, ay, aw, ah)) elif a.symbol() != (0, 0, 0, 0):
larger image, containing more sprites Returns: (int, int) -- the position of current sprite ''' return def update(): canvas_fill(canvas, (0, 0, 0)) arena.move_all() for a in arena.actors(): x1, y1, aw, ah = a.rect() draw_rect(canvas, (0, 255, 255), (x1, y1, 50, 50)) arena = Arena(1000, 1000) f1 = FallingBall(10, 10) f2 = FallingBall(70, 70) p1 = Plane(1, 350) p2 = Plane(1, 250) p3 = Plane(1, 150) arena.add(f1) arena.add(f2) arena.add(p1) arena.add(p2) arena.add(p3) canvas = canvas_init((1000, 1000)) set_interval(update, 1000 // 30)
pass def collide(self, other): if isinstance(other, Ball) and self._count == 0: self._raft = other def position(self): return self._x, self._y, self._w, self._h def symbol(self): return 0, 20, self._w, self._h ### arena = Arena(320, 240) b1 = Ball(arena, 40, 60, 5) b2 = Ball(arena, 80, 40, -5) turtle = Turtle(arena, 80, 80) def tick(): if g2d.key_pressed("ArrowUp"): turtle.go_up() elif g2d.key_pressed("ArrowRight"): turtle.go_right() elif g2d.key_pressed("ArrowDown"): turtle.go_down() elif g2d.key_pressed("ArrowLeft"): turtle.go_left() elif (g2d.key_released("ArrowUp") or g2d.key_released("ArrowRight") or
import g2d from actor import Actor, Arena from raft import Raft from fiume import Fiume from turtle import Turtle from vehicle import Vehicle from crocodile import Crocodile from land import Land from random import randint arena = Arena(600, 480) raft = Raft(arena, 0, 0, 0) turtle = Turtle(arena, 0, 0) crocodile = Crocodile(arena, 0, 0) class Frog(Actor): def __init__(self, arena, x, y): self._x, self._y = x, y self._w, self._h = 18, 15 self._speed = 7 self._dx, self._dy = 0, 0 self._arena = arena self._death = 0 self._collideraft = False self._collidefiume = False self._collideturtle = False self._collidecrocodile = False arena.add(self) def move(self):