def reset(self): self.sprites = g2d.load_image( "https://tomamic.github.io/images/sprites/moon-patrol.png") self.background = g2d.load_image( "https://tomamic.github.io/images/sprites/moon-patrol-bg.png") #self.game_over = g2d.load_image("moon-patrol-game-over.png") Not Working self._arena = self._game.arena() self._hero = self._game.hero() self._is_game_starting = True g2d.init_canvas(self._arena.size()) if self._settings['level'] == 'level_1': g2d.main_loop(self.level_1_tick) else: g2d.main_loop(self.level_2_tick)
def main(): global b1, b2, img b1 = FrogBall(40, 80) b2 = FrogBall(80, 40) g2d.init_canvas((ARENA_W, ARENA_H)) img = g2d.load_image("ball.png") g2d.handle_events(update, keydn, None) g2d.main_loop(5)
def __init__(self): self._game = BubbleBobbleGame() self._total_levels = self._game.total_levels() self._sprites = g2d.load_image("bubble-bobble.png") self._background = g2d.load_image("bubble-bobble-maps.png") self._menu = g2d.load_image("BB_main_menu.png") self._end = g2d.load_image("BB_end.png") self._ready = g2d.load_image("BB_ready_not-ready.png") self._x_y_background = [(0, 0), (0, 0), (512, 0), (0, 0), (0, 0)] self._player1_ready, self._player2_ready = False, False self._time_of_win, self._time_of_lost = 0, 0 self._current_level = 0 self._numbers_scores1 = [] self._numbers_scores2 = [] self._x1, self._x2 = 2, 450 self._win, self._lost = True, True g2d.init_canvas(self._game.arena().size()) g2d.main_loop(self.tick)
def main(): global arena, sprites arena = Arena(320, 240) Ball(arena, 40, 80) Ball(arena, 85, 40) Wall(arena, 115, 80, 100, 20) g2d.init_canvas(arena.size()) sprites = g2d.load_image("sprites.png") g2d.main_loop(tick)
def main(): global arena, turtle, sprites arena = Arena(320, 240) turtle = Turtle(arena, 80, 80) g2d.init_canvas(arena.size()) sprites = g2d.load_image("sprites.png") g2d.main_loop(tick)
def main(): global arena, turtle, sprites arena = Arena(320, 240) turtle = Turtle(arena, 80, 80) g2d.init_canvas(arena.size()) sprites = g2d.load_image("sprites.png") g2d.handle_events(update, keydown, keyup) g2d.main_loop()
def main(): global arena, sprites arena = Arena(320, 240) Ball(arena, 40, 80) Ball(arena, 85, 40) Wall(arena, 115, 80, 100, 20) g2d.init_canvas(arena.size()) sprites = g2d.load_image("sprites.png") g2d.handle_events(update) g2d.main_loop()
def main(): global arena, view_x, view_y, view_w, view_h, background arena = Arena(500, 250) FallingBall(arena, 40, 80) FallingBall(arena, 80, 40) Plane(arena, 60, 60) view_x, view_y, view_w, view_h = 0, 0, 300, 200 g2d.init_canvas((view_w, view_h)) background = g2d.load_image("https://raw.githubusercontent.com/tomamic/fondinfo/gh-pages/images/oop/viewport.png") g2d.main_loop(tick)
def main(): global sprites g2d.init_canvas(arena.size()) sprites = g2d.load_image("sprites.png") g2d.handle_events(update, keydown, keyup) g2d.main_loop()
import sys; sys.path.append('../examples/') import g2d def pt(x, y): p = Point() p.x, p.y = x, y return p ##cppyy.gbl.Point.__getitem__ = lambda self, key: getattr(self, "xy"[key]) ##cppyy.gbl.Rect.__getitem__ = lambda self, key: getattr(self, "xywh"[key]) arena = Arena(pt(480, 360)) b1 = Ball(arena, pt(40, 80)) b2 = Ball(arena, pt(80, 40)) g = Ghost(arena, pt(120, 80)) turtle = Turtle(arena, pt(80, 80)) sprites = g2d.load_image("sprites.png") def tick(): if g2d.key_pressed("ArrowUp"): turtle.go_up(True) elif g2d.key_released("ArrowUp"): turtle.go_up(False) if g2d.key_pressed("ArrowRight"): turtle.go_right(True) elif g2d.key_released("ArrowRight"): turtle.go_right(False) if g2d.key_pressed("ArrowDown"): turtle.go_down(True) elif g2d.key_released("ArrowDown"): turtle.go_down(False) if g2d.key_pressed("ArrowLeft"):
import g2d from time import time import cppyy cppyy.include("boardgame.h") from cppyy.gbl import BoardGame W, H = 40, 40 LONG_PRESS = 0.5 flag1 = g2d.load_image("flag.png") bomb = g2d.load_image("bomb.png") class BoardGameGui: def __init__(self, g: BoardGame): self._game = g self._downtime = 0 g2d.init_canvas(((g.cols() * W) + 250, g.rows() * H)) self.update_buttons() g2d.handle_mouse(self.mousedown, self.mouseup) def main_loop(self): g2d.main_loop() def mousedown(self, pos, button): self._downtime = time() def mouseup(self, pos, button): x, y = pos[0] // W, pos[1] // H if time() - self._downtime > LONG_PRESS:
''' @author Alberto Ferrari - https://albertoferrari.github.io/ @license This software is free - http://www.gnu.org/licenses/gpl.html animazione orizzontale ''' import g2d def update(): ''' modifica il canvas ''' global x # posizione pallina (globale) g2d.clear_canvas() # pulisce background g2d.draw_image(image, (x, 50)) # disegna immagine posizione(x,y) x = (x + dx) % 320 # modifica ascissa immagine g2d.init_canvas((320, 240)) # inizializzazione (320x200) image = g2d.load_image("ball.png") # caricamento immagine x = 0 # posizione iniziale pallina dx = 5 g2d.main_loop(update, 1000 // 30) # richiama funzione 30 volte al secondo
def __init__(self): self._game = BounceGame() g2d.init_canvas(self._game.arena().size()) self._sprites = g2d.load_image("sprites.png") g2d.main_loop(self.tick)
from fiume import Fiume from frog import Frog from vehicle import Vehicle from turtle import Turtle from land import Land from crocodile import Crocodile import pygame #Gestione audio veicoli = [] raft = [] frog = [] turtle = [] crocodile = [] land = [] arena = Arena(600, 480) logo = g2d.load_image("Frogger-logo.png") background = g2d.load_image("frogger_bg.png") sprite = g2d.load_image("frogger_sprites.png") gameover = g2d.load_image("gameover.png") win = g2d.load_image("win.png") pygame.mixer.init() pygame.mixer.music.load("froggeraudio.mp3") pygame.mixer.music.play() for i in range(0, 4): x = randint(100, 200) raft.append(Raft(arena, x, int((i * 40) + 80), 0)) raft.append(Raft(arena, x + 270, int((i * 40) + 80), 1)) raft.append(Raft(arena, x + 520, int((i * 40) + 80), 2)) for i in range(0, 4): if (i % 2 == 0): x = randint(100, 250)
def main(): global sprites g2d.init_canvas(arena.size()) sprites = g2d.load_image("sprites.png") g2d.main_loop(tick)
def make(typ, **attrs): obj = typ() for k, v in attrs.items(): setattr(obj, k, v) return obj def vals(obj, attrs=list("xywhrgb")): return tuple(getattr(obj, a) for a in attrs if hasattr(obj, a)) arena = Arena(make(Size, w=320, h=240)) b1 = Ball(arena, make(Point, x=40, y=80)) b2 = Ball(arena, make(Point, x=80, y=40)) g = Ghost(arena, make(Point, x=120, y=80)) turtle = Turtle(arena, make(Point, x=80, y=80)) sprites = g2d.load_image("sprites.png") def update(): arena.move_all() # Game logic g2d.clear_canvas() for a in arena.actors(): g2d.draw_image_clip(sprites, vals(a.symbol()), vals(a.position())) def keydown(key): if key == "ArrowUp": turtle.go_up() elif key == "ArrowDown": turtle.go_down() elif key == "ArrowLeft": turtle.go_left()
def main(): g2d.init_canvas((320, 240)) # inizializzazione (320x200) image = g2d.load_image("ball.png") # caricamento immagine g2d.main_loop(update, 1000 // 30) # richiama funzione 30 volte al secondo
#!/usr/bin/env python3 ''' @author Michele Tomaiuolo - http://www.ce.unipr.it/people/tomamic @license This software is free - http://www.gnu.org/licenses/gpl.html ''' import sys; sys.path.append('../examples/') import g2d x, y, dx, dy = 50, 50, 5, 5 count = 0 ARENA_W, ARENA_H = 320, 240 BALL_W, BALL_H = 20, 20 image = g2d.load_image("ball.png") def update(): global x, y, count g2d.clear_canvas() # Draw background g2d.draw_image(image, (x, y)) # Draw foreground if count < 5: x = (x + dx) % ARENA_W # Update ball's position y = (y + dy) % ARENA_H # Update ball's position count += 1 def keydn(code: str): global count if count == 5: count = 0 def main(): global dx, dy
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): g2d.draw_image_clip(sprites, a.symbol(), a.position()) else:
import g2d #g2d_pygame # way too much global stuff! x1, y1, dx1, dy1 = 40, 180, 5, 5 x2, y2, dx2, dy2 = 180, 140, 5, 5 ARENA_W, ARENA_H, BALL_W, BALL_H = 480, 360, 20, 20 image = g2d.load_image("ball.png") #controllo il codice che posso implementare per il grago # encapsulates behaviour, but exposes data def move_ball(x: int, y: int, dx: int, dy: int) -> (int, int, int, int): g = 0.5 if x + dx < 0 or x + dx + BALL_W > ARENA_W: dx = -dx x += dx if y + dy < 0 or y + dy + BALL_H > ARENA_H: dy = -dy else: dy += g y += dy return x, y, dx, dy def tick(): global x1, y1, dx1, dy1 global x2, y2, dx2, dy2 g2d.clear_canvas() # Draw background
(self._timer // self._interval)) return self._cx, self._cy, self._w, self._h def position(self) -> (int, int, int, int): return self._x, self._y, self._w, self._h def readcsv(file, line): with open('config/' + file) as csv: try: line = tuple(csv.readlines()[line].strip("\n").split(",")) return line except IndexError: return 0 record = int(readcsv('scores.csv', 0)[0]) playerlist = [] arena = Arena(1024, 512) image = g2d.load_image('spritemap.png') ground = int(readcsv('backgrounds.csv', 5)[2]) timer = 0 delay = 100 strkmode = False strkenemy = 0 amount = 0 warning = g2d.load_audio('sfx/warning.wav') laser = g2d.load_audio('sfx/laser.wav') menu = g2d.load_audio('sfx/mainmenu.wav') gameover = g2d.load_audio('sfx/gameover.wav')