ForumsProgramming ForumSimple python program help

3 5956
onark
offline
onark
7 posts
Nomad

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

games.init(screen_width=640,screen_height=480, fps = 50)



deathmessage=games.Message(value="GAME OVER", size=100, color= color.red, x=320,y=240,lifetime=150,after_death=games.screen.quit)
winmessage=games.Message(value="You Win!", size=100, color= color.blue, x=320,y=240,lifetime=150,after_death=games.screen.quit)

deathmessage.is_collideable=False

score=games.Text(value=0,size=50,color=color.red,x=20,y=20)

#_______________________TELEMARK____________________________________________________________________________________________________________________________

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)


#_____________________________EVIL____________________________________________________________________

class Evil(games.Sprite):

evilballimg=games.load_image("evilball.png",transparent=True)

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

  • 3 Replies
onark
offline
onark
7 posts
Nomad

it cut off the second part:

#_____________________________EVIL____________________________________________________________________

class Evil(games.Sprite):

evilballimg=games.load_image("evilball.png",transparent=True)

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

onark
offline
onark
7 posts
Nomad

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

onark
offline
onark
7 posts
Nomad

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

def add_one():
evilball=Evil()
games.screen.add(evilball)


#______________________________COIN________________________________________________________________________

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()


def main():
mountainimg = games.load_image("Mountains.png",transparent=False)
games.screen.background=mountainimg

games.mouse.is_visible=False

hero=Telemark()
games.screen.add(hero)

piece=Coin()
games.screen.add(piece)


#whether the mouse can exit the window or not, false=it can
games.screen.event_grab=False

games.screen.mainloop()

"""Kicking the program off"""
main()

Showing 1-3 of 3