It took be hour and a half to develop this simple game, and I've been working to debug it for 2 days now, i just cant find the problem, the games wont collide the evil ball and hero correctly or some other problem that you might encounter I believe i have provided ample comments to help you get familiarized with the program, this runs on the latest python a reply with comments on where i went wrong and how i can fix it would help and more general tips would be nice too, thanks!
the problem I might have with this program is that there are three classes and i might have not incorporated their interaction most efficiently
import random import pygame from livewires import games, color
class Telemark(games.Sprite): image=games.load_image("bluepointer.png",transparent=True) """Creates the text object for score and initializes the Telemarker object""" def __init__(self): super(Telemark,self).__init__(image=Telemark.image, x= 320, y=240) self.score=games.Text(value=0,size=50,top=20,right=20,color=color.red) score.is_collideable=False
def update(self): """Updates the user mouse to sprite, also spins it""" self.x=games.mouse.x self.y= games.mouse.y self.angle +=9 games.screen.add(score) self.checkcoincollision() self.checkevilcollision()
def checkcoincollision(self): """Checks for collisions with coins""" for Coin in self.overlapping_sprites: score.value += 10 if score.value == 100: score.right+=10 Coin.handlecollide()
def checkevilcollision(self): """Checks for collision with the evil objects""" for evilball in self.overlapping_sprites: self.destroy() games.screen.add(deathmessage)
def __init__(self): """Initializes where the evilball spawns as well as the image, also determines velocity and direction""" super(Evil,self).__init__(image=Evil.evilballimg, x=random.randint(10,630), y=random.randint(10,470), dx=random.randint(-1,1)+random.randint(-1,1)+random.randint(-1,1), dy=random.randint(-1,1)+random.randint(-1,1)+random.randint(-1,1)) def update(self): """checks for wall collision for the evilball""" if self.x+20>640 or self.x-20480 or self.y-20
def __init__(self): """Initializes where the evilball spawns as well as the image, also determines velocity and direction""" super(Evil,self).__init__(image=Evil.evilballimg, x=random.randint(10,630), y=random.randint(10,470), dx=random.randint(-1,1)+random.randint(-1,1)+random.randint(-1,1), dy=random.randint(-1,1)+random.randint(-1,1)+random.randint(-1,1)) def update(self): """checks for wall collision for the evilball""" if self.x+20>640 or self.x-20480 or self.y-20
sorry there is a limited number of char this leads off from the def update self in class evil you can combine all three and put it in notepad or something like that to view it as a whole.
def update(self): """checks for wall collision for the evilball""" if self.x+20>640 or self.x-20480 or self.y-20
it seems to cut off at that evil update part, lemme replace the greater than to ! and the less than to ^ even then, you should get the jist of the function, bouncing the object off of the walls of the screen.
def update(self): """checks for wall collision for the evilball""" if self.x+20(^)640 or self.x-20(!)0: self.dx = -self.dx if self.y+20(^)480 or self.y-20(!)0: self.dy = -self.dy
class Coin(games.Sprite): coinimg=games.load_image("coin.png",transparent=True) def __init__(self): """Initializes the x and y coordinates for which to place the coin""" super(Coin,self).__init__(image=Coin.coinimg, x=random.randint(10,630), y=random.randint(10,470)) def handlecollide(self): self.x=random.randint(10,630) self.y=random.randint(10,470) Evil.add_one()