How do I get this thing to work?

How do I get this thing to work?

Postby Hissing Cockroach » Mon Oct 07, 2013 9:48 pm

Hi, I have updated my "crosshairs" program to
where the target bounces around in squares, making
it harder to shoot, but now, it doesn't make bullet holes
when you click.Iv'e been trying to do this all day,
and just can't figure it out. Can anyone help?
Here is the code:

Code: Select all
import pygame, sys
from pygame.locals import *

pygame.init()

FPS = 30
FPSCLOCK = pygame.time.Clock()


DISPLAYSURF = pygame.display.set_mode((900,700),0,32)
pygame.display.set_caption('Animation')



WHITE = (255,255,255)
BLACK = (0,0,0)
img = pygame.image.load('target.png')
x = 10
y = 10
direction = 'right'

while True:
    DISPLAYSURF.fill(WHITE)

    if direction == 'right':
        x += 5
        if x == 280:
            direction = 'down'
    elif direction == 'down':
        y += 5
        if y == 220:
            direction = 'left'
    elif direction == 'left':
        x -= 5
        if x == 10:
            direction = 'up'
    elif direction == 'up':
        y -= 5
        if y == 10:
            direction = 'right'

    DISPLAYSURF.blit(img, (x,y))


    for event in pygame.event.get():
        mousex,mousey = pygame.mouse.get_pos()
        if event.type == QUIT:
            pygame.quit()
            sys.exit()

    pygame.draw.line(DISPLAYSURF, BLACK, (mousex - 2000, mousey), (mousex + 2000, mousey))
    pygame.draw.line(DISPLAYSURF, BLACK, (mousex, mousey - 2000), (mousex, mousey + 2000))

    pygame.display.update()
User avatar
Hissing Cockroach
 
Posts: 108
Joined: Sat Sep 14, 2013 2:35 pm
Location: Earth

Re: How do I get this thing to work?

Postby Mekire » Tue Oct 08, 2013 12:49 am

So, where's the code for the "bullet holes"? There is nothing in the code you posted that deals with mouse input like we covered in your other thread. You are also still using the star import and stilll doing everything in the global namespace, which leads me to believe you haven't followed any of the advice you have been given so far.

Your target should be a class. It will need to keep track of its location and the location of any holes in it. As the target will move, the holes will also move with it, so you need to know where they are relative to the target, not the screen. Also we don't have your target image so we can't really test anything.

-Mek

Edit:
Also, please try to use more descriptive titles for your threads. "Can't get this to work" doesn't provide any information.
User avatar
Mekire
 
Posts: 982
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: How do I get this thing to work?

Postby Hissing Cockroach » Tue Oct 08, 2013 2:05 am

I don't really see how the star import damages anything.
User avatar
Hissing Cockroach
 
Posts: 108
Joined: Sat Sep 14, 2013 2:35 pm
Location: Earth

Re: How do I get this thing to work?

Postby Mekire » Tue Oct 08, 2013 2:28 am

Hissing Cockroach wrote:I don't really see how the star import damages anything.

That is kind of the point.

You aren't experienced enough in the language to know how or why they are harmful. I can tell you however, that not one experienced member on this site would recomend you use it. The issue is not present in tiny programs; the issue comes in larger programs when it becomes impossible to locate where a name is coming from. The fact that one of our members went to the trouble to write a tutorial specifically addressing it should give you a clue that avoiding it is important.

Why ignore advice from more experienced programmers? Isn't that what you are here for?

-Mek
User avatar
Mekire
 
Posts: 982
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: How do I get this thing to work?

Postby dboxall123 » Tue Oct 08, 2013 10:04 am

I know you don't want to hear it, but like I said before, I think that you need to work through a Python tutorial before you try using Pygame.
dboxall123
 
Posts: 108
Joined: Fri Jul 12, 2013 5:28 pm


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest