hello
so i have this problem that i can't solve and i need ur help.
im making a program that makes the user move the fish and there is a shark at the end that he tries to avoid.
here is the code

kik="b.jpg"
kif="kf.jpg"
kis="sss.jpg"
#these are pictures
import pygame,sys
from pygame.locals import *

pygame.init()

screen=pygame.display.set_mode((600,480))
color=(255,222,124)
background=pygame.image.load(kik).convert()
fish=pygame.image.load(kif).convert()
shark=pygame.image.load(kis).convert()

x=0
movex=0
z=0



while True:
    for event in pygame.event.get():
        if event.type==QUIT:
            pygame.quit()
            sys.exit()
        if event.type==KEYDOWN:
            if event.key==K_ESCAPE:
                pygame.quit()
                sys.exit()
            if event.key==K_RIGHT:
                movex=+1
            if event.key == K_LEFT:
                movex=-1
            if event.key == K_SPACE:
                movex=0
            



    x+=movex
    z+=1
    screen.blit(background, (0,0))
    screen.blit(fish, (x,180))
    screen.blit(shark, (400,z))
    screen.blit(text, (300,200))
    
    if z >480:
        z=0

    pygame.display.update()

k i have to questions.
1. how can i make the fish stop when it touches the shark
2. how can i print text on the pygame window for example (oh noo u got killed)

thanks in advance

here is the code from above I modified so you could have all the stuff you wanted
in the code.

kik="b.jpg"
kif="kf.jpg"
kis="sss.jpg"
#these are pictures
import pygame,sys
from pygame.locals import *

pygame.init()

screen=pygame.display.set_mode((600,480))
color=(255,222,124)
background=pygame.image.load(kik).convert()
fish=pygame.image.load(kif).convert()
shark=pygame.image.load(kis).convert()

x=0
movex=0
z=0



while True:
    if x > 380 and x < 420 and z > 160 and z < 180:
        movex=0
        pygame.font.init()
        font = pygame.font.Font(None, 20)
        Text = font.Render("oh noo u got killed")
        screen.blit(Text, 50, 50)
    for event in pygame.event.get():
        if event.type==QUIT:
            pygame.quit()
            sys.exit()
        if event.type==KEYDOWN:
            if event.key==K_ESCAPE:
                pygame.quit()
                sys.exit()
            if event.key==K_RIGHT:
                movex=+1
            if event.key == K_LEFT:
                movex=-1
            if event.key == K_SPACE:
                movex=0
            



    x+=movex
    z+=1
    screen.blit(background, (0,0))
    screen.blit(fish, (x,180))
    screen.blit(shark, (400,z))
    screen.blit(text, (300,200))
    
    if z >480:
        z=0
    pygame.display.update()

I hope this will help you.

what's the specific problem with the code? Also have you tried livewires? It's a module for pygame and I prefer the simplicity. My first "game" I wrote in it is below, the only thing that would need to be modified would be collision detection on the sprites, and the event grab if you didn't want to use the mouse as I did.

from livewires import games

class Snake(games.Sprite):
    def update(self):
        if self.right>games.screen.width or self.left<0:
            self.dx= -self.dx
        if self.bottom>games.screen.height or self.top<0:
            self.dy=-self.dy

class Mouse_move(games.Sprite):
    def update(self):
        self.x=games.mouse.x
        self.y=games.mouse.y

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

image=games.load_image('lolpy.png', transparent=False)

games.screen.background=image

snake= games.load_image('pysnake.jpg', transparent=True)

snake= Snake(image=snake, x=320, y=240, dx=-1, dy=1)

g= games.load_image('g.jpg')
g= Mouse_move(image=g, x=games.mouse.x, y=games.mouse.y)

games.screen.add(snake)
games.screen.add(g)
games.mouse.is_visible=False
games.screen.event_grab=False
games.screen.mainloop()

oh, and the velocity of the shark, if you didn't want it bouncing all around the screen.

Thanks alot gus im trying them out all and i will post the most helpful
again thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.