def set_step_buttons(self): button_image = games.load_image("images/button.png") self.forward_button = games.Sprite(image = button_image, x = 680, y = 300, is_collideable = False) self.backward_button = games.Sprite(image = button_image, x = 530, y = 300) self.forward_text = MT.MyText('Forward', 20, color.black, 680, 300) self.backward_text = MT.MyText('Backward', 20, color.black, 530, 300) games.screen.add(self.forward_button) games.screen.add(self.backward_button) games.screen.add(self.forward_text) games.screen.add(self.backward_text)
def __init__(self): super(Game, self).__init__(image=Game.image, x=0, y=0) # Instructions Labels self.instructions = games.Text(value="Shoot as many ducks as possible in 1 minute!", size=35, x=320, y=100, color=color.white) self.instructions2 = games.Text(value="Press \"P\" To Pause", size=35, x=320, y=140, color=color.white) games.screen.add(self.instructions) games.screen.add(self.instructions2) # Paused Game Sprite self.paused = games.Sprite(image=games.load_image("Sprites/paused.png"), x=320, y=240, dx=0, dy=0) # Final Results Labels self.results = games.Text(value="", size=35, x=320, y=100, color=color.white) # How many ducks were hit self.results2 = games.Text(value="", size=35, x=320, y=140, color=color.white)# Accuracy # Counters to delay events self.spawnCounter = 0 self.menuCounter = 0 self.keyDelay = 0 self.keyDelayStart = False self.playing = False # Set to true after instructions go away # Create the timer for the game self.gameTimer = Clock() games.screen.add(self.gameTimer)
def __init__(self, x, y, game): super(Player, self).__init__(x=x, y=y, image=games.load_image("hidden\\char.png")) self.game = game self.default_image = self.image self.x = x self.y = y self.y_vel = 0 self.x_vel = 0 self.falling = True self.xflipped = False self.jumped = False self.gravity = 1 self.flop = False self.flopdown = 3 self.spawncoord = [] self.prevtime = time.time() self.paused = False self.pautime = 10 self.oldtime = time.time() self.time = time.time() self.pausething = games.Sprite( x=-10000, y=-10000, image=games.load_image("hidden\\paused.png")) games.screen.add(self.pausething) if self.game.level != 1: self.text = games.Text(x=400, y=50, size=50, color=color.red, value=str( math.ceil(10 * self.flopdown) / 10)) games.screen.add(self.text)
def __init__(self, game): self.spritelist = [] super(Cursor, self).__init__(x=100, y=200, image=games.load_image("hidden\\select.png")) self.game = game self.levels = open("hidden\\levels.txt", "r").read() self.positions = { 1: [100, 350], 2: [250, 350], 3: [400, 350], 4: [550, 350], 5: [700, 350] } for i in range(1, int(self.levels) + 1): thing = games.Sprite(x=self.positions[i][0], y=self.positions[i][1], image=games.load_image("hidden\\unbut.png")) self.spritelist.append(thing) games.screen.add(thing) text = games.Text(x=self.positions[i][0], y=self.positions[i][1], color=color.black, size=80, value=str(i)) self.spritelist.append(text) games.screen.add(text) for i in range(int(self.levels) + 1, 6): thing = games.Sprite(x=self.positions[i][0], y=self.positions[i][1], image=games.load_image("hidden\\lobut.png")) self.spritelist.append(thing) games.screen.add(thing) text = games.Text(x=self.positions[i][0], y=self.positions[i][1], color=color.black, size=80, value=str(i)) self.spritelist.append(text) games.screen.add(text) self.selected = 1 self.cooldown = 0 self.time = time.time() self.oldtime = time.time() self.levels = int(self.levels)
def main(): wall_image = games.load_image("wall.jpg", transparent=False) games.screen.background = wall_image pizza_image = games.load_image("pizza.bmp") the_pizza = games.Sprite(image=pizza_image, x=games.screen.width / 2, y=games.screen.height / 2, dx=1, dy=1) games.screen.add(the_pizza) games.screen.mainloop()
def addObjects(): games.screen.clear() """ Establish background. """ wallImage = games.load_image("waterbackground.jpg", transparent=False) games.screen.background = wallImage """ Create dock. """ dockImage = games.load_image("dock.gif") dock = games.Sprite(image=dockImage, x=0, y=240, is_collideable=False) games.screen.add(dock) """ Create the player. """ playerImage = games.load_image("playerImage.jpg") player = Player(image=playerImage, x=45, y=240, is_collideable=False) games.screen.add(player) games.screen.add(Player.score)
def main(): wallImage = games.load_image("waterbackground.jpg", transparent=False) games.screen.background = wallImage dockImage = games.load_image("dock.gif") dock = games.Sprite(image=dockImage, x=0, y=240) games.screen.add(dock) playerImage = games.load_image("playerImage.jpg") player = Player(image=playerImage, x=45, y=240) games.screen.add(player) for i in range(8): x = random.randint(700, 2000) y = random.randint(20, 460) piranhaImage = games.load_image("piranha.jpg") piranha = Piranha(image=piranhaImage, x=x, y=y, dx=-.25, dy=0) games.screen.add(piranha) games.screen.mainloop()
def main(): wallImage = games.load_image("waterbackground.jpg", transparent = False) games.screen.background = wallImage dockImage = games.load_image("dock.gif") dock = games.Sprite(image = dockImage, x = 0, y = 240) games.screen.add(dock) ## piranhaImage = games.load_image("piranha.jpg") ## piranha = games.Sprite(image = piranhaImage, x = 670, y = 240, dx = -.5, dy = 0) ## games.screen.add(piranha) ## piranhaImage = games.load_image("piranha.jpg") for i in range(8): x = random.randint(700, 1000) y = random.randint(0, games.screen.height) piranhaImage = games.load_image("piranha.jpg") piranha = Piranha(image = piranhaImage, x = x, y = y, dx = -.25, dy = 0) games.screen.add(piranha) games.screen.mainloop()
games.screen.mainloop() #Pizza Sprite #演示创建sprite from livewires import games games.init(screen_width=640, screen_height=480, fps=50) wall_image = games.load_image("wall.jpg", transparent=False) #设置图片背景 games.screen.background = wall_image #将披萨图片加载到内存中创建一个图片对象 pizza_image = games.load_image("pizza.bmp") #创建一个披萨sprite pizza = games.Sprite(image=pizza_image, x=320, y=240) #将sprite添加到图形屏幕 games.screen.add(pizza) games.screen.mainloop() #Big Score #演示在图形屏幕上显示文本 #引入color模块 from livewires import games, color games.init(screen_width=640, screen_height=480, fps=50) wall_image = games.load_image("wall.jpg", transparent=False) games.screen.background = wall_image
from livewires import games games.init(screen_width=640, screen_height=480, fps=50) wallImage = games.load_image("waterbackground.jpg", transparent=False) games.screen.background = wallImage dockImage = games.load_image("dock.gif") dock = games.Sprite(image=dockImage, x=0, y=240) games.screen.add(dock) games.screen.mainloop()
# Pizza Sprite # Demonstrates creating a sprite from livewires import games games.init(screen_width = 640, screen_height = 480, fps = 50) wall_image = games.load_image("wall.jpg", transparent = False) games.screen.background = wall_image pizza_image = games.load_image("pizza.bmp") pizza = games.Sprite(image = pizza_image, x = 320, y = 240) games.screen.add(pizza) games.screen.mainloop()
""" Program......: challenge12_3.py Author.......: Michael Rouse Date.........: 3/24/13 Description..: My Own version of "Duck Hunt" """ from livewires import games, color import pygame.display, pygame.mouse from random import randint, randrange # Setup game window games.init(screen_width=640, screen_height=480, fps=50) pygame.display.set_caption("Duck Hunt") # Tree and grass to bring to the front foreground = games.Sprite(image=games.load_image("Sprites/foreground.png"), left=0, bottom=390) games.screen.add(foreground) # CLASS ==================================== # Name.........: Cursor # Description..: Sets mouse to the crosshair # Syntax.......: Cursor() # ========================================== class Cursor(games.Sprite): """ Cursor Object """ clicked = False xPos = games.mouse.x yPos = games.mouse.y def __init__(self):
# Moving pizza # demos moving around sprites from livewires import games games.init(screen_width=640, screen_height=480, fps=60) wall_image = games.load_image("wall.jfif", transparent=False) games.screen.background = wall_image pizza_image = games.load_image("pizza.jfif") the_pizza = games.Sprite(image=pizza_image, x=games.screen.width/2, y=games.screen.width/2, dx=1, dy=1) games.screen.add(the_pizza) games.screen.mainloop()
# Летающий burger # движущиеся спрайты from livewires import games games.init(screen_width=640, screen_height=480, fps=50) wall_image = games.load_image("wall.jpg", transparent=False) games.screen.background = wall_image burger_image = games.load_image("burger_syrom_fri.png") the_burger = games.Sprite(image=burger_image, x=games.screen.width / 2, y=games.screen.height / 2, dx=1, dy=1) games.screen.add(the_burger) games.screen.mainloop()
# Ничего себе результат! # Демонстрирует отображение текста на графическом экране from livewires import games, color games.init(screen_width=640, screen_height=480, fps=50) wall_image = games.load_image("wall.jpg", transparent=False) # transparent - прозрачность, по умолчанию True, но фон ВСЕГДА =False games.screen.background = wall_image pizza_image = games.load_image("pizza.bmp") pizza = games.Sprite( image=pizza_image, x=games.screen.width / 2, #высота окна пополам y=games.screen.height / 2, dx=1, #скорость(положительное - вправо) dy=1) #скорость(положительное - вниз) games.screen.add(pizza) score = games.Text( value=1756521, # Text передать минимум 5 аргументов size=60, # шрифт (высота в пикселях) color=color.black, # константа из модуля color x=550, # Text - подкласс Sprite y=30) won_message = games.Message( value="Ураааа!", size=100, # Message - подкласс Text color=color.red, x=games.screen.width / 2, #высота окна пополам y=games.screen.height / 2, lifetime=250, #секунд, по умолчанию 0(не разрушается)
def set_pause_button(self): button_image = games.load_image("images/button.png") self.pause_button = games.Sprite(image = button_image, x = 600, y = 300) self.pause_text = MT.MyText('Pause', 20, color.black, 600, 300) games.screen.add(self.pause_button) games.screen.add(self.pause_text)
#inserting a background from livewires import games games.init(screen_width=640, screen_height=440, fps=50) countryScene = games.load_image("WinterBranches.jpg", transparent=False) games.screen.background = countryScene #inserting a sprite owl_image = games.load_image("owl.png") owl = games.Sprite(image=owl_image, x=420, y=60) games.screen.add(owl) games.screen.mainloop()
# Спрайт-бургер from livewires import games games.init(screen_width=640, screen_height=480, fps=50) wall_image = games.load_image("wall.jpg", transparent=False) games.screen.background = wall_image burger_image = games.load_image("burger_syrom_fri.png") burger = games.Sprite(image=burger_image, x=320, y=240) games.screen.add(burger) games.screen.mainloop()
# Pizza Sprite # Demonstrates creating a sprite from livewires import games games.init(screen_width=640, screen_height=480, fps=50) wall_image = games.load_image("wall.jpg", transparent=False) games.screen.background = wall_image pizza_image = games.load_image("pizza.bmp") pizza = games.Sprite(image=pizza_image, x=320, y=240) #default: 'Transparency' = (True) games.screen.add(pizza) games.screen.mainloop()
from livewires import games games.init(screen_width=640, screen_height=440, fps=50) countryScene = games.load_image("WinterBranches.jpg", transparent=False) games.screen.background = countryScene butterfly_image=games.load_image("flyingOwl.png") butterfly=games.Sprite(image=butterfly_image, x=0, y=0, dx=3, dy=3) games.screen.add(butterfly) games.screen.mainloop()