Python Forum
I want to add a bullet function to my game. how would i go about it?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I want to add a bullet function to my game. how would i go about it?
#1
I'm relatively new to python and I'm currently following a tutorial for a fighting game in pygame, but i want to add my own changes and additions. I'm trying to add a shooting function, but i have no idea how to go about it. I've seen the list method but don't know how to implement it because my game uses a player class and a main function, and i want to be able to assign the function to a button press.
.py   Even Cooler.py (Size: 2.35 KB / Downloads: 49)
.py   Player.py (Size: 6.75 KB / Downloads: 53)
Reply
#2
I would write Bullet as a subclass of Sprite. When firing a bullet I would add a bullet object to a Group. The bullet group will keep track of all the fired bullets, calling their update methods and removing bullets that collide with another sprite (like a player).
Reply
#3
is Sprite the Player class? also, would i make a list and append the bullet object to it? is a Group a list? sorry for asking so many questions at once, i just want to be sure of what I'm doing.
Reply
#4
Sprites and Groups may be the most important concepts in pygame. If they were not mentioned in your tutorial, I don't think the tutorial was very good.
Iyjja likes this post
Reply
#5
(Jan-02-2024, 05:23 PM)Iyjja Wrote: I'm relatively new to Python and I'm currently following a tutorial for a fighting game in Pygame, but I want to add my own changes and additions. I'm trying to add a shooting function, but I have no idea how to go about it. I've seen the list method but don't know how to implement it because my game uses a player class and a main function, and I want to be able to assign the function to a button press.

If you want to add shooting in your pygame-based game you need to modify the player class to include a bullets list and a shoot method and create a Bullet class for bullet attributes and methods in the main function, called player. shoot() on a key press to spawn bullets.
Iyjja likes this post
Reply
#6
(Jan-04-2024, 06:11 PM)deanhystad Wrote: Sprites and Groups may be the most important concepts in pygame. If they were not mentioned in your tutorial, I don't think the tutorial was very good.

i found a video that explains how to use sprites and groups. i think this is what i needed, thanks!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Bullet firing skillamac 1 2,459 Aug-07-2020, 09:56 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020