def __init__(self, name='untitled', par=3, origin=Point(50, 50), width=1080, height=900, ball=None, **labeled_groups): self.score = -1 self.name = name self.par = par self.origin = origin self.width = width self.height = height self.image = Surface((width, height)) self.rect = pygame.Rect(*origin.as_2d_tuple(), width, height) self.groups = {'all': LayeredDirty()} for label, group in labeled_groups.items(): self.groups[label] = group self.groups['all'].add(*group.sprites()) self.ball = GolfBall(ball, 0, self.groups['all']) if ball else None
def init_sprites(self): """temp, this will go in the init.""" sprite_list = [self.elephant, self.cat, self.score_text] self.allsprites = LayeredDirty(sprite_list, _time_threshold=1000 / 10.0) scene = self self.shark = Shark(self.allsprites, scene, self.width, self.height) self.allsprites.add(self.shark) self.allsprites.clear(self.screen, self.background)
def __init__(self, engine, *, background_color=(0, 0, 55), container_class=GameObjectCollection, **kwargs): super().__init__(engine) self.background_color = background_color self.background = engine.display.copy() self.background.fill(self.background_color) self.game_objects = container_class() self.render_group = LayeredDirty()
def __init__(self, engine, *, background_color=(0, 0, 100), container_class=GameObjectCollection, set_up=None, **kwargs): super().__init__(engine) self.background_color = background_color self.background = None self.game_objects = container_class() self.render_group = LayeredDirty() if set_up is not None: set_up(self)
def __init__(self, engine): super().__init__(engine, background_color=(10, 21, 41)) self.render_group = LayeredDirty() self.spawn_objects = [InfiniteObjectManager(self, Chimney, self.groups[config.KEY_CHIMNEY])] self.spawner = Spawner() self.spawn_objects.append(self.spawner) santa = Santa(self, Vector(*self.engine.display.get_rect().center), self.groups[config.KEY_GIFTS], self.groups[config.KEY_SANTA]) self.controller = Controller(actor=santa) channel = resources.sounds["santaclauseiscoming"].play(-1) channel.set_volume(0.1) self.score = 0 self.missed_chimneys = 0 Score(self, lambda: self.score, self.groups[config.KEY_UI])
def __init__(self, screen: Surface): ''' Constructor of the class, takes the screen to gain control over the render of the game objects ''' # Get display info info = Info() # Get Clock to ensure frame rating self.clock = Clock() # The default return value of the Scene self.return_value = -1 # Set the continue condition self.running = True # Get the relevant information from info self.screen_h, self.screen_w = info.current_h, info.current_w # Set the screen of the Scene self.screen: Surface = screen # Main Sprite groups self.event_group = Group() self.update_group = Group() self.render_group = LayeredDirty()
from pygame import Color, font from pygame.math import Vector2 from pygame.sprite import LayeredDirty from src.models import Hole as BaseHole from src.sprites import * from src.utils import colors, Point Hole = BaseHole('Hole #12', par=5, origin=Point(80, 30, 0), ball=Point(440, 125, 0), noncollidibles=LayeredDirty( Text(Point(530, 15), 'Par 5', font.Font(None, 30), colors.WHITE), ), collidibles=LayeredDirty( Green([ Point(50, 50, 0), Point(500, 50, 0), Point(500, 200, 0), Point(100, 200, 0), Point(100, 450, 0), Point(50, 450, 0) ]), Slope([ Point(100, 200, 0), Point(200, 200, 0), Point(200, 450, 0), Point(100, 450, 0) ], Color(200, 0, 0, 255), Vector2(0.3, 0.0)), Sand([
def applyColour(self, colour): """Very simple colour substitution""" for x in range(0, self.rect.width): for y in range(0, self.rect.height): pixel = self.image.get_at((x, y)).r if (pixel > 50): self.image.set_at((x, y), colour) # create sprites bg = PpuiImage("assets/lcars_screen_1.png") button = PpuiImage("assets/button.png") button.applyColour((255, 204, 153)) # add sprites to layer sprites = LayeredDirty() sprites.add(bg) sprites.add(button) # event loop while pygame.display.get_init(): sprites.draw(screenSurface) pygame.display.update() for event in pygame.event.get(): if event.type == KEYUP: pygame.quit() break if (event.type == MOUSEMOTION): # move button around as mouse moves (or touch-drag)
def addGroup(): newGroup = LayeredDirty() groupList.append(newGroup)
from pygame import Color, font from pygame.math import Vector2 from pygame.sprite import LayeredDirty from src.models import Hole as BaseHole from src.sprites import * from src.utils import colors, Point Hole = BaseHole( 'Hole #13', par=3, origin=Point(100, 0, 0), ball=Point(495, 315, 0), noncollidibles=LayeredDirty( Text(Point(775, 605), 'Par 3', font.Font(None, 30), colors.WHITE), ), collidibles=LayeredDirty( Green([ Point(440, 260, 0), Point(540, 260, 0), Point(540, 360, 0), Point(440, 360, 0) ]), Slope([ Point(440, 360, 0), Point(510, 360, 0), Point(510, 410, 0), Point(470, 410, 0), Point(470, 460, 0), Point(440, 460, 0) ], Color(200, 0, 0, 255), Vector2(0.5, 0.5)), Slope([
def init(cls): cls.contents = LayeredDirty() cls.clock = time.Clock()
from pygame import Color, font from pygame.math import Vector2 from pygame.sprite import LayeredDirty from src.models import Hole as BaseHole from src.sprites import * from src.utils import colors, Point Hole = BaseHole( 'Hole #4', par=4, origin=Point(50, 100, 0), ball=Point(312, 580, 0), noncollidibles=LayeredDirty( Text(Point(900, 268), 'Par 4', font.Font(None, 30), colors.WHITE), ), collidibles=LayeredDirty( Green([Point(250, 600, 0), Point(250, 150, 0), Point(370, 150, 0), Point(370, 250, 0), Point(770, 250, 0), Point(770, 150, 0), Point(870, 150, 0), Point(870, 400, 0), Point(770, 400, 0), Point(770, 300, 0), Point(370, 300, 0), Point(370, 600, 0)]), Slope([Point(250, 150, 0), Point(250, 90, 0), Point(370, 90, 0), Point(370, 150, 0)], Color(100, 0, 0, 255), Vector2(0.0, -0.7)), Sand([Point(250, 90, 0), Point(250, 50, 0), Point(370, 50, 0), Point(370, 90, 0)]), Slope([Point(410, 250, 0), Point(410, 200, 0), Point(770, 200, 0), Point(770, 250, 0)], Color(100, 0, 0, 255), Vector2(-0.33, -0.6)), Slope([Point(410, 300, 0), Point(410, 360, 0), Point(770, 360, 0), Point(770, 300, 0)], Color(100, 0, 0, 255), Vector2(-0.33, 0.6)), Rough([Point(410, 200, 0), Point(410, 150, 0), Point(770, 150, 0), Point(770, 200, 0)]), Rough([Point(770, 400, 0), Point(410, 400, 0), Point(410, 360, 0), Point(770, 360, 0)]), Pin(Point(840, 275, 0)), Money(Point(305, 200)), Wall(Point(250, 50, 0), Point(370, 50, 0), 5), Wall(Point(370, 50, 0), Point(370, 250, 0), 5), Wall(Point(370, 250, 0), Point(410, 250, 0), 5), Wall(Point(410, 250, 0), Point(410, 150, 0), 5),
from pygame import Color, font from pygame.math import Vector2 from pygame.sprite import LayeredDirty from src.models import Hole as BaseHole from src.sprites import * from src.utils import colors, Point Hole = BaseHole( 'Hole #3', par=3, origin=Point(50, 50, 0), ball=Point(253, 555, 0), noncollidibles=LayeredDirty( Text(Point(850, 183), 'Par 3', font.Font(None, 30), colors.WHITE) ), collidibles=LayeredDirty( Green([Point(180, 140, 0), Point(830, 140, 0), Point(830, 240, 0), Point(310, 240, 0), Point(310, 590, 0), Point(180, 590, 0)]), Rough([Point(310, 240, 0), Point(380, 240, 0), Point(380, 590, 0), Point(310, 590, 0)]), Sand([Point(380, 240, 0), Point(830, 240, 0), Point(830, 310, 0), Point(380, 310, 0)]), Pin(Point(780, 190, 0)), Money(Point(773, 265)), Wall(Point(180, 140, 0), Point(830, 140, 0), 5), Wall(Point(830, 140, 0), Point(830, 310, 0), 5), Wall(Point(830, 310, 0), Point(380, 310, 0), 5), Wall(Point(380, 310, 0), Point(380, 590, 0), 5), Wall(Point(380, 590, 0), Point(180, 590, 0), 5), Wall(Point(180, 590, 0), Point(180, 140, 0), 5) ) )
from pygame import Color, font from pygame.math import Vector2 from pygame.sprite import LayeredDirty from src.models import Hole as BaseHole from src.sprites import * from src.utils import colors, Point Hole = BaseHole( 'Hole #7', par=4, origin=Point(50, 50, 0), ball=Point(255, 630, 0), noncollidibles=LayeredDirty( Text(Point(805, 70), 'Par 4', font.Font(None, 30), colors.WHITE)), collidibles=LayeredDirty( Green([ Point(50, 500, 0), Point(450, 500, 0), Point(450, 700, 0), Point(50, 700, 0) ]), Slope([ Point(200, 500, 0), Point(300, 500, 0), Point(300, 325, 0), Point(200, 325, 0) ], Color(125, 0, 0, 255), Vector2(0.0, -0.1)), Rough([ Point(200, 325, 0), Point(200, 200, 0),
from pygame import Color, font from pygame.math import Vector2 from pygame.sprite import LayeredDirty from src.models import Hole as BaseHole from src.sprites import * from src.utils import colors, Point Hole = BaseHole('Hole #10', par=2, origin=Point(50, 75, 0), ball=Point(485, 690, 0), noncollidibles=LayeredDirty( Text(Point(810, 340), 'Par 2', font.Font(None, 30), colors.WHITE), ), collidibles=LayeredDirty( Rough([ Point(300, 430, 0), Point(340, 430, 0), Point(340, 470, 0), Point(300, 470, 0) ]), Rough([ Point(630, 430, 0), Point(670, 430, 0), Point(670, 470, 0), Point(630, 470, 0) ]), Slope([ Point(300, 430, 0), Point(260, 390, 0),
from pygame import Color, font from pygame.math import Vector2 from pygame.sprite import LayeredDirty from src.models import Hole as BaseHole from src.sprites import * from src.utils import colors, Point Hole = BaseHole( 'Hole #6', par=3, origin=Point(150, 100, 0), ball=Point(200, 630, 0), noncollidibles=LayeredDirty( Text(Point(88, 92), 'Par 3', font.Font(None, 30), colors.WHITE)), collidibles=LayeredDirty( Water([ Point(150, 150, 0), Point(150, 550, 0), Point(550, 550, 0), Point(550, 150, 0) ]), Green([ Point(150, 550, 0), Point(550, 550, 0), Point(550, 700, 0), Point(150, 700, 0) ]), Green([ Point(150, 150, 0), Point(150, 50, 0),
import pygame, sys, os, time from pygame.locals import * from pygame import font from pygame.sprite import DirtySprite, LayeredDirty pygame.init() global allFont allFont = font.SysFont("monospace",11) # set up the window global MAINWINDOW MAINWINDOW = pygame.display.set_mode((1200, 1000), 0, 32) pygame.display.set_caption('Character Generator') global fullWindowGroup fullWindowGroup = LayeredDirty() global groupList groupList = [] groupList.append(fullWindowGroup) def drawSquare(xposition,yposition,length,color): pygame.draw.rect(MAINWINDOW, color, (xposition,yposition,length,length)) def drawRect(rect,color): r = pygame.draw.rect(MAINWINDOW, color, rect) return r #groups def addGroup(): newGroup = LayeredDirty() groupList.append(newGroup) def drawGroup(group): dirty = group.draw(MAINWINDOW) pygame.display.update(dirty) def drawAllGroups(): for g in groupList: drawGroup(g)
from pygame import Color, font from pygame.math import Vector2 from pygame.sprite import LayeredDirty from src.models import Hole as BaseHole from src.sprites import * from src.utils import colors, Point Hole = BaseHole( 'Hole #8', par=2, origin=Point(50, 50, 0), ball=Point(145, 520, 0), noncollidibles=LayeredDirty( Text(Point(708, 20), 'Par 2', font.Font(None, 30), colors.WHITE), Text(Point(925, 310), 'Is this lava?', font.Font(None, 24), colors.WHITE) ), collidibles=LayeredDirty( Green([Point(50, 50, 0), Point(50, 580, 0), Point(250, 580, 0), Point(250, 200, 0), Point(650, 200, 0), Point(650, 50, 0)]), Rough([Point(650, 50, 0), Point(800, 50, 0), Point(800, 200, 0), Point(650, 200, 0)]), Lava([Point(250, 580, 0), Point(250, 200, 0), Point(800, 200, 0), Point(800, 50, 0), Point(900, 50, 0), Point(900, 580, 0)]), Pin(Point(730, 125, 0)), Money(Point(225, 175)), Wall(Point(50, 50, 0), Point(900, 50, 0), 5), Wall(Point(900, 50, 0), Point(900, 580, 0), 5), Wall(Point(900, 580, 0), Point(50, 580, 0), 5), Wall(Point(50, 580, 0), Point(50, 50, 0), 5) ) )
def init(cls): cls.objects = LayeredDirty() cls.selected_objects = []
from pygame import Color, font from pygame.math import Vector2 from pygame.sprite import LayeredDirty from src.models import Hole as BaseHole from src.sprites import * from src.utils import colors, Point Hole = BaseHole( 'Hole #11', par=3, origin=Point(75, 50, 0), ball=Point(180, 680, 0), noncollidibles=LayeredDirty( Text(Point(900, 75), 'Par 3', font.Font(None, 30), colors.WHITE), ), collidibles=LayeredDirty( Green([Point(130, 620, 0), Point(230, 620, 0), Point(230, 730, 0), Point(130, 730, 0)]), Rough([Point(230, 730, 0), Point(230, 680, 0), Point(350, 680, 0), Point(350, 730, 0)]), Slope([Point(230, 620, 0), Point(230, 540, 0), Point(350, 540, 0), Point(350, 620, 0)], Color(200, 0, 0, 255), Vector2(0.15, 0.4)), Green([Point(230, 620, 0), Point(230, 680, 0), Point(350, 680, 0), Point(350, 620, 0)]), Rough([Point(350, 460, 0), Point(470, 460, 0), Point(470, 730, 0), Point(350, 730, 0)]), Green([Point(470, 620, 0), Point(710, 620, 0), Point(710, 680, 0), Point(590, 680, 0), Point(590, 730, 0), Point(470, 730, 0)]), Green([Point(650, 620, 0), Point(650, 310, 0), Point(790, 310, 0), Point(790, 620, 0)]), Sand([Point(790, 620, 0), Point(790, 560, 0), Point(880, 560, 0), Point(880, 620, 0)]), Water([Point(790, 560, 0), Point(790, 450, 0), Point(880, 450, 0), Point(880, 560, 0)]), Sand([Point(790, 450, 0), Point(790, 310, 0), Point(880, 310, 0), Point(880, 450, 0)]), Slope([Point(470, 510, 0), Point(470, 390, 0), Point(650, 390, 0), Point(650, 510, 0)], Color(200, 0, 0, 255), Vector2(-0.2, -0.15)), Green([Point(470, 460, 0), Point(130, 460, 0), Point(130, 310, 0), Point(470, 310, 0)]), Rough([Point(470, 390, 0), Point(470, 190, 0), Point(560, 190, 0), Point(560, 390, 0)]),
from pygame import Color, font from pygame.math import Vector2 from pygame.sprite import LayeredDirty from src.models import Hole as BaseHole from src.sprites import * from src.utils import colors, Point Hole = BaseHole('Hole #1', par=1, origin=Point(50, 50, 0), ball=Point(535, 545, 0), noncollidibles=LayeredDirty( Text(Point(515, 160), 'Par 1', font.Font(None, 30), colors.WHITE), ), collidibles=LayeredDirty( Green([ Point(360, 190, 0), Point(700, 190, 0), Point(700, 600, 0), Point(360, 600, 0) ]), Pin(Point(535, 260, 0)), Money(Point(529, 215)), Wall(Point(360, 190, 0), Point(700, 190, 0), 5), Wall(Point(700, 190, 0), Point(700, 600, 0), 5), Wall(Point(700, 600, 0), Point(360, 600, 0), 5), Wall(Point(360, 600, 0), Point(360, 190, 0), 5)))
from pygame import Color, font from pygame.math import Vector2 from pygame.sprite import LayeredDirty from src.models import Hole as BaseHole from src.sprites import * from src.utils import colors, Point Hole = BaseHole('Hole #2', par=2, origin=Point(50, 50, 0), ball=Point(390, 575, 0), noncollidibles=LayeredDirty( Text(Point(670, 140), 'Par 2', font.Font(None, 30), colors.WHITE)), collidibles=LayeredDirty( Green([ Point(440, 210, 0), Point(540, 210, 0), Point(540, 510, 0), Point(640, 510, 0), Point(640, 630, 0), Point(340, 630, 0), Point(340, 510, 0), Point(440, 510, 0) ]), Rough([ Point(440, 210, 0), Point(340, 210, 0), Point(340, 90, 0), Point(640, 90, 0),