def __init__(self, width, height): super().__init__(width, height) dishtxt = TextAsset(text="Radar Dish", width=200, align='center', style='10px Arial', fill=black) signaltxt = TextAsset(text="Signal (moving)", width=200, align='center', style='10px Arial', fill=red) #suntxt = TextAsset(text="Random Sun", width = 200, align = 'center', style = '10px Arial', fill=black) #planetxt = TextAsset(text="Plane (will idealy move)", width = 200, align = 'center', style = '10px Arial', fill=black) Sprite(RectangleAsset(1000, 500, thinlinesb, skyblue), (0, 0)) dish((100, 450)) Sprite(dishtxt, (45, 450)) signal((100, 450)) Sprite(signaltxt, (75, 375)) plane((cpx, cpy)) #plane1((cpx,cpy)) #plane((900,72)) #Sprite(planetxt,(865,25)) if rainny == 1: for x in range(0, 31): rain((random.randrange(400, 800), random.randrange(0, 500))) if snowy == 1: for x in range(0, 31): snow((random.randrange(400, 800), random.randrange(0, 500))) if foggy == 1: fog((200, 0)) Sprite(LineAsset(1000, 1, thinline), (0, 500)) Sprite(CircleAsset(20, thinlinesun, sun), (200, 100))
def timeGame(self): remaining = self.gameTime - time() + self.start if remaining < 0: remaining = 0 if score[0] > score[1]: winner = 'Player 1 wins!' elif score[1] > score[0]: winner = 'Player 2 wins!' else: winner = "It's a draw!" TimeUpText(TextAsset("Time's up! " + winner, width=SCREEN_WIDTH), (SCREEN_WIDTH / 2, SCREEN_HEIGHT / 6)) self.getSpritesbyClass(ScoreText)[0].destroy() #self.go = False self.transparency = 1 self.direction = 0 #self.restart = True self.stage = 'restart' self.listenKeyEvent('keydown', 'space', self.restartGame) seconds = remaining % 60 if seconds < 10: placeholder = ':0' else: placeholder = ':' TimeText( TextAsset( str(int(remaining // 60)) + placeholder + str(int(seconds))), (SCREEN_WIDTH / 2, SCREEN_HEIGHT / 4))
def __init__(self, width, height): super().__init__(width, height) black = Color(0, 1) yellow = Color(0xffeb3b, 1.0) white = Color(0xfafafa, 1.0) liner = LineStyle(1, white) line = LineStyle(1, black) self.play = False self.ComicSans = True bg_asset = RectangleAsset(width, height, line, black) bg = Sprite(bg_asset, (0, 0)) text = TextAsset("Press ENTER To Start", style='40pt Comic Sans MS', fill=Color(0xffeb3b, 1), width=700) self.prompt = Sprite(text, (50, 250)) TEXT = TextAsset("Game Over", style='40pt Comic Sans Ms', fill=Color(0xffeb3b, 1), width=700) self.Prompt = Sprite(TEXT, (350, 350)) self.prompt.visible = True self.Prompt.visible = False self.count = 0 self.lost = False Kong.listenKeyEvent("keydown", "enter", self.playing)
def step(self): for x in self.labels: if x[2] != x[1].hp: x[0].destroy() if x[1].hp > 0: if x[3] == 'M': pic = TextAsset(str(x[1].hp), style='bold 16px Times', fill=Color(0x070E68, 0.9)) else: pic = TextAsset(str(x[1].hp), style='bold 16px Helvetica', fill=Color(0x8C2727, 0.9)) pict = Sprite(pic, (x[1].x + 33, x[1].y + 84)) a = x[3] self.labels.append([pict, x[1], x[1].hp, a]) self.labels.remove(x) else: x[0].x = x[1].x + 40 x[0].y = x[1].y + 84 mems = 0 memdeath = 0 enems = 0 enemdeath = 0 for char in self.getSpritesbyClass(Member): if (char.title == 'a' and self.akey == 'True') or ( char.title == 'b' and self.bkey == 'True') or (char.title == 'c' and self.ckey == 'True'): char.comm = 0 else: char.comm = 1 mems += 1 if char.state != 'dead': char.step() else: char.setImage(3) char.spot.claimed = 0 memdeath += 1 for char in self.getSpritesbyClass(Enemy): enems += 1 if char.state == 'dead': enemdeath += 1 char.v = 0 char.setImage(3) else: char.step() for x in self.getSpritesbyClass(Bullet): x.step() for x in self.getSpritesbyClass(Cover): x.step() if self.state == 'none': if memdeath == mems: print('You lose.') self.state = 'loss' elif enemdeath == enems: print('You win!') self.state = 'win'
def guessletter(self): global wordinprogress global word global displayedword global wordsprite global alreadyguessedstring global guessedasset global wordasset global hangingphase global gallows global guessedsprite global allletters displayedword = '' guessedletter = input('Please guess a letter!') guessedletter = guessedletter.lower() while alreadyguessed.count(guessedletter) > 0: guessedletter = input('You already guessed that letter! Try again:') while allsymbols.count(guessedletter) > 0: guessedletter = input("That's not a letter! Try again:") while len(guessedletter) > 1: guessedletter = input("Please only input one letter:") if word.count(guessedletter) > 0: for x in range(len(word)): if guessedletter == word[x]: wordinprogress = wordinprogress[:x] + "{0}".format(guessedletter) + wordinprogress[x+1:] for x in range(len(wordinprogress)): displayedword = displayedword + "{0:<3}".format(wordinprogress[x]) self.wordsprite.destroy() wordasset = TextAsset(displayedword, style='60px Helvetica',align='center',width=1000) self.wordsprite = Sprite(wordasset,(500,525)) self.wordsprite.fxcenter = 0.5 alreadyguessed.append(guessedletter) alreadyguessedstring = alreadyguessedstring + "{0:<3}".format(guessedletter) else: alreadyguessed.append(guessedletter) alreadyguessedstring = alreadyguessedstring + "{0:<3}".format(guessedletter) self.gallows.hangingphase += 1 self.gallows.setImage(self.gallows.hangingphase) self.guessedsprite.destroy() guessedasset = TextAsset(alreadyguessedstring, style='20px Helvetica',align='center',width=100) self.guessedsprite = Sprite(guessedasset, (100,250)) self.endgame() self.wongame()
def __init__(self): super().__init__() self.width = 0.15 * SCREEN_WIDTH self.height = 0.15 * SCREEN_HEIGHT self.buttoncolors = [ blue, red, green, yellow, cyan, magenta, orange, purple, gray ] self.buttons = [ ((x % 3 - 1) / 5 * SCREEN_WIDTH + SCREEN_WIDTH / 2 - self.width / 2, (x // 3 - 1) / 5 * SCREEN_HEIGHT + SCREEN_HEIGHT / 2 - self.height / 2, self.buttoncolors[x]) for x in range(9) ] self.start = 0 #self.go = False self.frameTime = 0 self.deltaTime = 0 self.gameTime = 90 TitleText( TextAsset('Head Soccer!', width=SCREEN_WIDTH, style='50pt Helvetica'), (SCREEN_WIDTH / 2, SCREEN_HEIGHT / 4)) self.listenMouseEvent('mousedown', self.placeButtonsEvent) #self.intro = True #self.restart = False self.transparency = 1 self.direction = 0 self.playercolors = [] self.stage = 'intro'
def __init__(self): super().__init__() black = Color(0, 1) noline = LineStyle(0, black) back_asset = ImageAsset("images/e36d28c490fe26653e50fbd17025f3ef.jpg") back = Sprite(back_asset, (0,0)) back.scale=1.4 self.text=Sprite(TextAsset("Game Over", width=700, align='center',style='70px Arial', fill=Color(0xff2222,1)), (300,350)) self.text.visible= False SpaceShip((40,100)) Asteroid((400,400)) Asteroid((50,30)) Asteroid((800,300)) moon_asset=ImageAsset("images/super-moon.png") moon= Sprite(moon_asset, (300, 200)) moon.scale=0.2
def __init__(self, width, height): super().__init__(width, height) for x in range(self.width // Stars.width + 1): for y in range(self.height // Stars.height + 1): Stars((x * Stars.width, y * Stars.height)) self.sun = Sun((self.width / 2, self.height / 2)) self.ship1 = Ship1(self, (self.width / 2 - 140, self.height / 2), (0, -120), self.sun) self.ship2 = Ship2(self, (self.width / 2 + 140, self.height / 2), (0, 120), self.sun) self.tsprites = { k: Sprite( TextAsset(text=v, width=200, align='center', style='20px Arial', fill=Color(0xff2222, 1))) for k, v in Spacewar.strings.items() } self.tsprites['winner'].visible = False self.tsprites['winner'].y = self.height / 2 self.tsprites['tie'].visible = False self.tsprites['tie'].position = (self.width / 2 - 100, self.height / 2 + 50) self.tsprites['space'].position = (self.width / 2 - 100, self.height * 3 / 4) self.tsprites['left'].position = (self.width / 4 - 50, self.height / 2) self.tsprites['right'].position = (self.width * 3 / 4 - 50, self.height / 2) self.state = 'instructions' self.listenKeyEvent('keydown', 'space', self.space)
def __init__(self, arg): super().__init__(arg) self.image = ImageAsset("bunny.png") self.rocket = ImageAsset("ggimages/rocket.png") self.multiimage = ImageAsset("bunny.png", Frame(2, 2, 10, 14), 3, 'horizontal', 2) color = 0x001122 alpha = 0.5 self.c = Color(color, alpha) pixels = 9 self.l = LineStyle(pixels, color) self.rect = RectangleAsset(10, 20, LineStyle(3, Color(0x112233, 0.5)), Color(0x223344, 0.6)) self.circ = CircleAsset(30, LineStyle(3, Color(0x112233, 0.5)), Color(0x223344, 0.6)) self.ellipse = EllipseAsset(40, 50, LineStyle(4, Color(0x113355, 0.6)), Color(0x224466, 0.7)) self.line = LineAsset(60, 70, LineStyle(5, Color(0x224466, 0.7))) self.poly = PolygonAsset([(10, 10), (20, 10), (15, 15), (10, 10)], LineStyle(6, Color(0x665544, 0.9)), Color(0x664422, 1.0)) self.text = TextAsset("sample text", style="20px Arial", width=200, fill=Color(0x123456, 1.0), align='center')
def __init__(self, app, position): global Game asset = TextAsset(app.score, style="30pt Times New Roman", width=Game.width, fill=Color(0x000000, 1.0)) super().__init__(asset, position)
class Text(Sprite): text = TextAsset("Flappy Bird XTREME", style="bold 40pt Arial", width=250, fill=yellow) def __init__(self, position): super().__init__(Text.text, position)
def endgame(self): if self.gallows.hangingphase == 6: self.wordsprite.destroy() wordasset = TextAsset(finishedword, style='60px Helvetica',align='center',width=1000,fill=red) self.wordsprite = Sprite(wordasset,(500,525)) self.wordsprite.fxcenter = 0.5 Hangman.unlistenMouseEvent('mousemove', myapp.mousemove) Hangman.unlistenMouseEvent('mousedown', myapp.mousedown)
def switch(self, event): global stage stage += 1 #print("news! ", stage) an indicator if stage == 1: self.txt4.visible = False self.txt5.visible = False self.txt3.visible = False self.txt9.visible = False if stage == 2: print("You are done dragging and dropping!") middle1 = TextAsset( "Now you can draw on the screen by dragging the", width=500) middle2 = TextAsset( "mouse across the screen while pressing down both the mouse and", width=700) middle3 = TextAsset( "one of the following keys: 'q', 'r', 'o', 'p', 'g', 'l', or 'b' .", width=500) self.txt6 = Sprite(middle1, (wth2, h2)) self.txt7 = Sprite(middle2, (wth2, (h2 + 20))) self.txt8 = Sprite(middle3, (wth2, (h2 + 40))) self.txt9a = Sprite(other, (wth2, (h2 + 95))) self.txt3a = Sprite(hide, (wth2, (h2 + 60))) if stage == 3: print( "Now try dragging the mouse across the screen while holding one of the following keys: 'b', 'r', 'p', 'l', 'g', 'o', or 'q'." ) self.txt6.visible = False self.txt7.visible = False self.txt8.visible = False self.txt3a.visible = False self.txt9a.visible = False if stage == 4: end1 = TextAsset("You have finished this program!", width=500) end2 = TextAsset( "If you ctrl+click, you can save or copy your image.", width=500) self.txt1 = Sprite(end1, (wth2, h2)) self.txt2 = Sprite(end2, (wth2, h2 + 20)) self.txt3.visible = True if stage == 5: self.txt1.visible = False self.txt2.visible = False self.txt3.visible = False
def mousePosition(event): global text global coords if coords != None: coords.destroy() xcurse.y = event.y-7 ycurse.x = event.x-9 text = TextAsset("(" + str(round((event.x-959)/20)) + "," + str(round((-(event.y-507))/20)) + ")", style = '10pt Arial') coords = Sprite(text, (event.x-7, event.y-22))
def __init__(self, *args, **kwargs): """ Required Inputs * **pos** position of label * **text** text contents of label """ super().__init__(TextAsset(""), *args, **kwargs) self._touchAsset()
def __init__(self, width, height): super().__init__(width, height) time.time() black = Color(1, 1) line = LineStyle(2, black) self.peanuts = 0 Score = str(self.peanuts) grass = Color(0x229954, 1) hedge = Color(0x145A32, 1) stone = Color(0xB2BABB, 1) road = Color(0x515A5A, 1) roof = Color(0x5F6A6A, 1) Grass = RectangleAsset(1279, 939, line, grass) Hedge = RectangleAsset(25, 700, line, hedge) Hedge2 = RectangleAsset(25, 340, line, hedge) Hedge3 = RectangleAsset(25, 290, line, hedge) Hedge4 = RectangleAsset(485, 25, line, hedge) Stone = RectangleAsset(20, 50, line, stone) Road = RectangleAsset(60, 940, line, road) Roof = RectangleAsset(30, 400, line, roof) Roof2 = RectangleAsset(30, 300, line, roof) self.score = TextAsset("Score:" + Score + "", style="40pt Comic Sans MS", fill=Color(0xD2B4DE, 1), width=200) self.waituntil = time.time() + 1 X = random.randrange(100) + 1280 X2 = random.randrange(100) + 1380 Y = random.randrange(940) Sprite(Grass, (0, 0)) Sprite(Roof2, (200, 0)) Sprite(Roof2, (200, 600)) Sprite(RectangleAsset(-400, 30, line, roof), (0, 0)) Sprite(CircleAsset(45, line, roof), (215, 40)) Sprite(CircleAsset(25, line, roof), (215, 40)) Sprite(CircleAsset(45, line, roof), (215, 900)) Sprite(CircleAsset(25, line, roof), (215, 900)) People((X2, 300)) People((X, 320)) People((X2, 340)) People((X, 360)) People((X2, 380)) People((X, 400)) People((X2, 420)) People((X, 440)) People((X2, 460)) People((X, 480)) People((X2, 500)) People((X, 520)) People((X2, 540)) People((X, 560)) People((X2, 580)) self.prompt = Sprite(self.score, (10, 10)) Bingo((640, 300), self)
def placeButtons(self): self.stage = 'buttons' for x in self.buttons: Button(RectangleAsset(self.width, self.height, thinline, x[2]), (x[0], x[1])) self.listenMouseEvent('mousedown', self.buttonClick) for x in [('1', 0.15 * SCREEN_WIDTH, 0.5 * SCREEN_HEIGHT), ('2', 0.85 * SCREEN_WIDTH, 0.5 * SCREEN_HEIGHT)]: PlayerColor(TextAsset('Player ' + x[0] + ' color:', width=128), (x[1], x[2]))
def __init__(self, width, height): global stage super().__init__(width, height) self.a = 0 print("Welcome! Click and drag the icons to duplicate them.") abun = Bunny((65, 500), True) acat = Cat((80, 350), True) atree = Tree((75, 225), True) aflr = Flowr((50, 105), True) abird = Bird((65, 600), True) aboi = kid((55, 710), True) Sprite(box, (132, 25)) Sprite(label, (50, 30)) start1 = TextAsset("Click on an icon to select it.", width=500) start2 = TextAsset( "Click somewhere else to place a copy of that icon there.", width=500) self.txt3 = Sprite(hide, (wth2, h2 + 40)) self.txt4 = Sprite(start1, (wth2, h2)) self.txt5 = Sprite(start2, (wth2, (h2 + 20))) self.txt9 = Sprite(other, (wth2, (h2 + 75))) #self.txt3b = Sprite(hide, (wth2,(h2+40))) Draw.listenKeyEvent("keydown", "enter", self.switch) Draw.listenKeyEvent("keydown", "g", self.green) Draw.listenKeyEvent("keydown", "q", self.turq) Draw.listenKeyEvent("keydown", "o", self.orange) Draw.listenKeyEvent("keydown", "b", self.black) Draw.listenKeyEvent("keydown", "p", self.purp) Draw.listenKeyEvent("keydown", "r", self.brn) Draw.listenKeyEvent("keydown", "l", self.pale) Draw.listenMouseEvent("mousedown", self.mse_isdn) Draw.listenMouseEvent("mouseup", self.mseno) Draw.listenMouseEvent("mousemove", self.move) Draw.listenKeyEvent("keyup", "g", self.no_col) Draw.listenKeyEvent("keyup", "q", self.no_col) Draw.listenKeyEvent("keyup", "o", self.no_col) Draw.listenKeyEvent("keyup", "b", self.no_col) Draw.listenKeyEvent("keyup", "p", self.no_col) Draw.listenKeyEvent("keyup", "r", self.no_col) Draw.listenKeyEvent("keyup", "l", self.no_col)
def test_textasset(self): t = TextAsset( "sample text", style="20px Arial", width=200, fill=Color(0x123456, 1.0), align="center", ) self.assertEqual(t.gfx.text, "sample text") self.assertEqual(t.gfx.styledict["font"], "20px Arial") self.assertEqual(t.gfx.styledict["fill"], 0x123456) self.assertEqual(t.gfx.alpha, 1.0)
def removeheart(self): if self.count >= 0: self.count -= 1 self.heartlist[self.count].destroy() if self.count <= 0: self.text = Sprite( TextAsset("GAME OVER:( your heart shrunk two sizes too small!", width=1000, align='center', style='30px Arial', fill=Color(0xff2222, 1)), (100, 150)) myapp.gameover = True
def flashText(self, text, ypos): classDestroy(FlashingText) FlashingText( TextAsset(text, width=SCREEN_WIDTH, style='20pt Helvetica', fill=Color(0x000000, self.transparency)), (SCREEN_WIDTH / 2, ypos)) if self.transparency == 1: self.direction = -0.01 elif self.transparency == 0: self.direction = 0.01 self.transparency += self.direction self.transparency = round(self.transparency, 2)
def scoreChange(totalscore): #print(Present1.totalscore) shift = 0 for i in range(len(Score.scores)): i = i - shift Score.scores[i].destroy() del Score.scores[i] shift += 1 s_asset = TextAsset(("Presents Delivered: {0}!!").format(totalscore), width=500, align='left', style='30px Arial', fill=Color(0xff222, 1)) Score.scores.append(Sprite(s_asset, (0, 0)))
def timer(): global cT, timeCounter, timeList, timeReset if timeReset==True: cT=time.time timeReset=False elif time.time()-cT>1: if len(timeList)>0: for x in timeList: x.destroy() timeAsset= TextAsset(timeCounter) timeList.append(Sprite(timeAsset, (100,100))) timeReset = True print(timeList) else: print('no change')
def __init__(self, width, height): super().__init__(width, height) black = Color(0, 1) noline = LineStyle(0, black) bg_asset = ImageAsset("images/starfield.jpg") txt_asset= TextAsset(text="Press R to Reset", width=200, align='center',style='20px Arial', fill=Color(0xff2222,1)) star0 = Sprite(bg_asset, (0,0)) star1= Sprite(bg_asset, (512,0)) star2= Sprite(bg_asset, (0,512)) star3= Sprite(bg_asset, (512, 512)) txt = Sprite(txt_asset, (0,0)) Sunthing((500,360)) SpaceShip((300,300)) '''
def hit2(self): elapsed = time.time() if elapsed > self.end: print(self.dead) self.dead.destroy() global t t = 1 if self.lives == 0: gameoverT = TextAsset("Final Score: {0}".format(score)) Sprite(gameoverT, (myapp.width - 150, 40)) if SCREEN_WIDTH1 / 1071 < SCREEN_HEIGHT / 571: self.go = Sprite(gameover, (1, 1)) self.go.scale = SCREEN_WIDTH1 / 1071 else: self.go = Sprite(gameover, (1, 1)) self.go.scale = SCREEN_HEIGHT / 571
def doFuncs(self): for i in self.getSpritesbyClass(drawnPoint): del i for i in range(0,len(self.functions)): try: b = funcInterpreter("y","x", self.functions[i][0], initial)[0] except: print("func failed") try: b = funcInterpreter("y","x", self.functions[i][0], self.initial + self.increase / 2)[0] except: print("Function Failed, Going to (0,0)", self.functions[i]) b = (0,0) point((getX(b[0]),getY(b[1])), colorRandom(i), self.functions[i][0], self.functions[i][1]) Sprite(TextAsset(self.functions[i][0], width=100, align='center',style='12px Arial', fill=black),(5,(i)*frameHeight/20+2)) print(self.functions[i][0], self.functions[i][1])
def buttonClick(self, event): for x in self.buttons: if x[0] <= event.x <= x[0] + self.width and x[ 1] <= event.y <= x[1] + self.height: self.playercolors.append(x[2]) if len(self.playercolors) == 1: pos = 0.15 else: pos = 0.85 PlayerColor( RectangleAsset(0.05 * SCREEN_WIDTH, 0.05 * SCREEN_HEIGHT, thinline, x[2]), (pos * SCREEN_WIDTH - 64, 0.5 * SCREEN_HEIGHT + 15)) if len(self.playercolors) == 1: Instructions( TextAsset('Press "q" to change colors', width=SCREEN_WIDTH), (SCREEN_WIDTH / 2, 50)) self.listenKeyEvent('keydown', 'q', self.changeColors) else: self.stage = 'ready' self.listenKeyEvent('keydown', 'space', self.begin)
def guessword(self): global word global hangingphase global gallows global finishedword global guessed guessedword = input("Guess the word!") guessedword = guessedword.lower() if guessedword == word: self.wordsprite.destroy() wordasset = TextAsset(finishedword, style='60px Helvetica',align='center',width=1000) self.wordsprite = Sprite(wordasset,(500,525)) self.wordsprite.fxcenter = 0.5 endscreen = Sprite(winscreenasset, (150,250)) guessed = True self.wongame() else: self.gallows.hangingphase += 1 self.gallows.setImage(self.gallows.hangingphase) self.endgame()
class ScoreText(Sprite): asset = TextAsset('Goal!') def __init__(self, position): super().__init__(ScoreText.asset, position) self.fxcenter = self.fycenter = 0.5 self.visible = False global score score = [0, 0] self.placeScore() def goal(self, Goal): score[Goal.ident] += 1 self.placeScore() def placeScore(self): classDestroy(ScoreNum) ScoreNum(TextAsset(score[0]), (SCREEN_WIDTH / 8, SCREEN_HEIGHT / 2)) ScoreNum(TextAsset(score[1]), (SCREEN_WIDTH * (7 / 8), SCREEN_HEIGHT / 2))
def step(self): thetime = time.time() for ship in self.getSpritesbyClass(Bingo): ship.step() for hip in self.getSpritesbyClass(People): hip.step() if hip.x <= 230: hip.x = 1280 self.peanuts = self.peanuts - 10 if thetime > self.waituntil: self.waituntil = thetime self.prompt.destroy() self.peanuts = self.peanuts + .01 peanuts = self.peanuts Score = str(peanuts) self.score = TextAsset("Score:" + Score + "", style="40pt Comic Sans MS", fill=Color(0xD2B4DE, 1), width=200) self.prompt = Sprite(self.score, (10, 10))