Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need a way to get a list of all sprites in a certain area of the screen, and I cannot find one anywhere on the internet.
Can someone please give me an example code of how to do this?
If it helps, all the sprites are in an "active" list.
Depends on whether you have obstacles or not, i.e. what the definition of "In the Area" means and also home many sprites you are dealing with.
If there's not many sprites and the distance calc is fast then brute force is probably ok.
for sprite in sprites:
if something.distance(sprite) < THRESHOLD:
do_something_with_near_sprite(sprite)
If you have a lot of sprites have a look at quadtrees and things like that. If calculating the distance is complicated then you're probably going to want to look at A* algorithm. There are libraries for these things so you shouldn't have to implement them yourself unless you want to.
This is a pretty general question (prepare to have it voted down by others :)
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I want to make a game in the turtle module similar to "Lunar Lander" by Atari but I'm not sure if I'll be able to make a collision system if I draw the terrain using a turtle. Any help would be appreciated.
I don't think python turtle have the collision system, but you can make the limit for the ground. Such as if the ground surface is on -40y, then you can create a variable and prevent the object from going through the ground.
groundLimit = -40 #create the limit for the object
while True:
if turtle.ycor() < 40: #check if the object hit the ground
turtle.sety(40) #make the object on the ground again
#but this method might make the object a bit weird
But if you are making a game, I would suggest using the "pygame" module. It's great for making games and better than turtle. Turtle is just for drawing, but pygame is for making games. You can find tutorials online to help you.
Good Luck!
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am making a python game and I am not exactly sure how to make the enemy's and the player have collisions. Could someone show me a easy way to add collisions to multiple things efficiently. I want the enemy in my python game to collide with the player. Here is the code I use to move the enemy to the player. This code moves the enemy but the enemy does not collide with the player.
if self.canvas.coords(self.man)[0] > self.canvas.coords(Man1.man)[0]:
self.canvas.move(self.man,-1,0)
if self.canvas.coords(self.man)[0] < self.canvas.coords(Man1.man)[0]:
self.canvas.move(self.man,1,0)
if self.canvas.coords(self.man)[1] < self.canvas.coords(Man1.man)[1]:
self.canvas.move(self.man,0,1)
if self.canvas.coords(self.man)[1] > self.canvas.coords(Man1.man)[1]:
self.canvas.move(self.man,0,-1)
You can use the canvas.overlapping() which returns all the items in a given rectangle. Just give it the x,y coordinates of one of your objects and see if the tuple returns more than one.
if you show us some code or give more details we might be able to better help you
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
So I am attempting to make a little audio player using Pygame. I wanted to add a little audio visualizer similar to in Windows Media Player. I was thinking of starting with an audio wave that scrolls across the screen. But I'm not sure where to start.
Right now I'm just using pygame.mixer to start, stop, and pause the music. I think I would have to use pygame.sndarray and get some samples but I don't know what to do from there. What can I do to turn those samples into a visual audio wave?
Check out the pygame.draw methods.
You can probably take the audio values and map them to one of the draw options - like draw.arc or draw.line. You will have to map the signal output to values that remain within the X and Y max and min of the viewport.
Processing can do the same thing, but is a bit easier to implement if you are interested in learning the scripting language. It has methods specifically for doing the mapping for you and you can do some pretty extreme visuals without a lot of code.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I need to make a simple board game for school in python it has to have a grid sort of like a chess board individual spaces where the character can stand. But I have no idea how, we are not allowed to download anything since it's school computers. Also I need to make the character move. I just need this is the most simple form. The example the book gave us looked like this:
..........
..P.......
..........
..T.......
....T.....
..........
..T.......
..........
.........X
P is the player, T is a trap and X is the treasure. I don't need it exactly like that I just need a board like that and how to make the player move on it.
As this question is not very precise the answer can't be as well; but maybe there are some general hints:
-think about how to store the positions of the elements on the boards (lists (-> lines of the game) might be a good start)
-think about what it means to move the figure (taking the list approach this means you can increment or decrement the position in the list or switch to another one)
-think about how you could see that the player has fallen in to a trap/won (check if a position is already acquired before moving the figure)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am making simple game. (A matrix where players can take cells(x,y), only one player on one cell, and they acquire new cells after the player before). Every player has a unique color. I am trying to find out if one player has surrounded cells of other users. In which case all cells are going to change color. Is there any known algorithm for this problem, to check only when user plays a new move ?
I would suggest that you take a look at a flood fill algorithm, these are simple algorithms that searches from a start point and tries to fill the board. You would simply have to check if the fill algorithm can reach the end of the board or not.