Finding an algorithm is usually best done with a data structure that makes the algorithm easy.
In this case, your territory.
The territory should be an unordered (O(1) hash) set of borders and elements.
Whenever you add an element to the territory, you iterate over adjacent tiles and see if they should be a border tile; in this case, they are a border ...
If you need to find edges of holes in the middle of your territory too, then your linear in the area of the territory bound is the best we can do. Any tile on the interior could potentially be a hole that we need to count, so we need to look at every tile in the area bounded by the territory's outline at least once to be sure we've found all the holes.
Notice: Whether or not a tile is on the boundary only depends on it and its neighbors.
Because of that:
It is easy to run this query lazily. For instance: You do not need to search for the boundary on the whole map, only on what is visible.
It is easy to run this query in parallel. In fact, I could image some shader code that does this. And if you need it ...
Looking in the code, the library provides noise.randomize() which states:
Randomize the permutation table used by the noise functions. This
makes them generate a different noise pattern for the same inputs.
Thus, randomizing the function through the API provided is the most direct way to solve the problem.
Here's an alternative solution based ...
Move your area up one tile, then up-right, then down right, etc..
Afterwards remove the original area.
Merging all six sets should be O(n), sorting O(n.log(n)), set difference O(n).
If the original tiles are stored in some sorted format, the merged set can be sorted in O(n) too.
I don't think there is an algorithm with less than O(n), since you need to ...
A quick recap of how Perlin noise works:
It starts by finding the cell your sample point lands in within an integer lattice. From that it determines the integer points that define the corners of that cell. For each corner, it generates a pseudo-random gradient vector, and then computes the projection of your sample point's offset from the corner along this ...
Take a look at the pygame.transform.rotate method. It allows you to transform the drawing surface temporarily (don't forget to transform it by the inverse rotation afterwards) so that anything you draw will be rotated.
Now, as far as calculating the angle to transform by, the pygame.transform.rotate method, unlike most rotate methods in libraries like this, ...
So you have a "one-button" gameplay and it's not engaging enough? Have you played NFSU? It had a drag race mode, which is basically pressing one button in perfect timing to outrace other competitors.
Why not try to replace turns with cooldowns. Whenever someone's cooldown reaches zero - they can have their turn and try to press the button in perfect time. ...
First, instead of storing each platform as a member in class, do it like this:
self.platforms=[Platform(200, 550), Platform(600, 550), Platform(1000, 550)]
It's the list of all platforms in the game. By storing them in the list, you'll be able to easily add or remove them.
Do the same for each object that's going to be more than one in the game (coins, ...
As you've pointed out, the other question you linked to is more about how to render a nice graph and numerical change, and not how to decide exactly how or why the number should change. It just states...
You start at time T1. You're going towards time T2. Price at time T1 is P1. P2 is end price.
You generate a random number (probably based on some events, ...
When you use something like self.foo.bar = self from the class bar, you're telling foo which bar it is linked to. Basically,
self.scene = scene
self.scene.manager = self
is used to set reference in both ways, so that from the SceneManager, you can know which scene is managed, and from the scene, you can get access to the scene manager through the ...
The code formatting for your answer has mostly broken down, it would be a lot easier to help you if you fixed it.
What does it mean for turtles to collide? It means that they occupy the same space, so the easiest thing to do is:
if player.position() == player2.position():
however, this doesn't quite work because turtle ...
I just wrote a blog post about how to do this. This uses the first method that @DMGregory mentioned starting with an edge cell and marching around the perimeter. It's in C# instead of Python but should be pretty easy to adapt.
I'm not sure if it would work well, as I'm not familiar with pygame, but you could stick the value that you want in your Dog object as a float, and do calculations on this value, then use this value converted to int to update the rect.y variable.
Dog.computation_y += 0.5
Dog.rect.y = math.floor(Dog.computation_y)
You'll be able to control a bit more the ...
pygame.sprite.groupcollide returns a dictionary that always includes the sprites in the first group. Therefore, the if test you have written will always return true.
You should re-write the function to check whether or not there are sprites in the list for every sprite in the dog group.
If your grass tile's position in the tilemap is <Gx,Gy> then its pixel position in the game world will be:
tile_worldX = Gx * Tile_Size
tile_worldY = Gy * Tile_Size
Then you subtract the position of the screen's top-left corner from these coordinates to get their on-screen pixel position:
tile_screenX = tile_worldX - view_x
tile_screenY = ...
You will need to fix your update method and add some variables to your Bullet class:
# Bullet Class
def __init__(self, vx, vy):
self.image = pygame.Surface([4,10])
self.rect = self.image.get_rect()
self.velocity_x = vx
self.velocity_y = ...
You need to write while difficulty < 1 and difficulty > 3. A comparision needs two elements, and the second statement is currently missing the left hand side operand. Note that the statement does not ever evaluate to true, since an integer cannot be smaller than one and larger than three at the same time. You probably meant to use or here.
You should do if-elif-elif with e.type.
First import the event constants you need to check from pygame.constants
from pygame.constants import QUIT, MOUSEBUTTONDOWN
for e in pygame.event.get():
if e.type == QUIT:
#close the game
elif e.type == MOUSEBUTTONDOWN:
The dir() ...
There's no way to do this automatically, so if you want some sort of automation for the surface rescaling, you'd need to write your own wrapper class around pygame.Rect, that owns a rectangle, and takes in a surface, and resizes the surface when a method of the wrapper is called.
The resizing function you are looking for is pygame.transform.scale. Pass it a ...
I have never worked with Pygame, but are you not defining on init self.onGround = false?
self.falling = True
self.onGround = False
self.v = 0
That would mean that if jump is called, nothing happens.
if self.onGround == False:
self.velocity = 8
self.onGround = False
Maybe there is something else you ...
This often happens also if you do not specify the context before compiling the shaders.
For example, for QT Widgets (pytqt) you should have your shaders compiled when the gl context is enabled, for example in the initializeGL function.
So in the case of using QT you can do something like:
class MyQtWidget(QOpenGLWidget, QWidget):
def __init__(self, ...
So there's a couple steps to this:
You need a list to handle the log messages.
You need a function to print events to the list. How you do this is up to you, but it needs to be a function you can call whenever these events happen. Something as simple as a custom print function works just fine. Here's a quick idea of how to make the log itself:
list = 
Please use the function pygame.key.set_repeat(delay, interval) once before starting the infinite while loop.
I use as delay 1 and an interval of 25.
From the docs: pygame.key module
The delay is the number of milliseconds before the first repeated pygame.KEYDOWN will be sent.
After that another pygame.KEYDOWN will be sent every interval milliseconds.
I believe that this is what you were looking for:
keys = pygame.key.get_pressed() # checking pressed keys
if keys[pygame.K_ESCAPE]: # If 'esc' - QUIT GAME
game_exit = True
if keys[pygame.K_RIGHT]: # If 'right' - MOVE RIGHT
The longer you hold the key down, the more it would move