Hi everyone. Well I've been trying to figure this out for a quite a long time now by looking at some examples and searching the web, reading some tutorials and so on, but I don't even know where to start yet. Can you explain to me about the sprites too and how I can use them or at least link me to a tutorial? But my main concern is how am I suppose to get the mouse click position and make the bullet travel in its direction until it disappears from the screen or it hits an object (Which I don't have yet as well).

Thanks, Dan08.

For a look at pygame sprites see:
http://www.cs.iupui.edu/~aharris/pygame/ch06/basicSprite.py

Here is an example for finding the mouse position ...

import pygame as pg

# pygame uses (r, g, b) tuples for color
red = (255, 0, 0)
white = (255, 255, 255)

screen = pg.display.set_mode((500, 500))
pg.display.set_caption("click the mouse on the window ...")

# create a little red square
red_square = pg.Surface((30, 30))
red_square.fill(red)

# starting position
xy_position = (100, 100)

# set up the event loop
running = True
while running:
    event = pg.event.poll()
    keyinput = pg.key.get_pressed()
    # exit on corner 'x' click or escape key press
    if keyinput[pg.K_ESCAPE]:
        raise SystemExit
    elif event.type == pg.QUIT:
        running = False
    elif event.type == pg.MOUSEBUTTONDOWN:
        #print(event.pos)  # test
        xy_position = event.pos

    # this erases the old sreen
    screen.fill(white)
    # put the image on the screen at given position
    screen.blit(red_square, xy_position)
    # update screen
    pg.display.flip()

Well, I know how to detect the mouse position and make the object rotate towards it, I just don't know how I'm supposed to make the bullet move forward until it disappears or hits an object (which doesn't exist yet). I've uploaded an example with the images and everything.

Thanks, Dan08.

Edited 5 Years Ago by Dan08: n/a

Find out formula for line going through mouse to where it points to and how to count distance between bullet and object (hint: math.hypot of delta)

This article has been dead for over six months. Start a new discussion instead.