Circle collision, pop-up error "CreaCir' object has no attribute 'radio'" - python

I make a program where I generate circles of random size and position, by means of classes in python, I have managed to generate the circles as I wish but all collide with each other, so I have created a method so that this does not happen but it generates an error that I can not identify "'CreaCir' object has no attribute 'radio'", so I do not know what I'm doing wrong, the terminal tells me that the error is in the circle class in the collision method in the return, if someone could mark my error and give me advice to fix it I would appreciate it.
my code is as follows. first my circle class where I contain the collision method:
class Circulo(PosGeo):
def __init__(self, x, y, r):
self.x = x
self.y = y
self.radio = r
self.cx = x+r
self.cy = y+r
def dibujar(self, ventana):
pg.draw.circle(ventana, "white", (self.x, self.y), self.radio, 1)
def update(self):
pass
def colisionC(self, c2):
return self.radio + c2.radio > sqrt(pow(self.cx - c2.cx, 2) + pow(self.cy - c2.cy, 2))#where I get the error
now a part of my main code:
class CreaCir:
def __init__(self, figs):
self.i = 1
self.r = randint(5, 104)
self.x = randint(0, 500 + self.r)
self.y = randint(0, 300 + self.r)
self.creOne = Circulo(self.x, self.y, self.r)
self.figs.append(self.creOne)
def update(self):
if self.i <100:
choca = False
self.r = randint(5, 104)
self.x = randint(0, 500 + self.r)
self.y = randint(0, 300 + self.r)
self.creOne = Circulo(self.x, self.y, self.r)
for j in range (self.i):
choca = self.creOne.colisionC(self.figs[j])#here is where I use the collision method to my object
if choca == True:
break
if choca == False:
self.figs.append(self.creOne)
self.i+=1
def dibujar(self, ventana):
pass
called:
class Ventana:
def __init__(self, Ven_Tam= (700, 500)):
pg.init()
self.ven_tam = Ven_Tam
self.ven = pg.display.set_caption("Linea")
self.ven = pg.display.set_mode(self.ven_tam)
self.ven.fill(pg.Color('#404040'))
self.figs = []
self.figs.append(CreaCir(self.figs))
self.reloj = pg.time.Clock()
def check_events(self):
for event in pg.event.get():
if event.type == pg.QUIT or (event.type == pg.KEYDOWN and event.key == pg.K_ESCAPE):
quit()
pg.display.flip()
def run(self):
while True:
self.check_events()
for fig in self.figs:
fig.update()
for fig in self.figs:
fig.dibujar(self.ven)
self.reloj.tick(30)
if __name__ == '__main__':
ven = Ventana()
ven.run()

The cause of the error is that you have put a CreaCir object in the figs list. So the first item in figs (self.creOne.colisionC(self.figs[j])) is a CreaCir object and this object has no radio.
Just remove that line of code, it is absolutely unnecessary.
self.figs.append(CreaCir(self.figs))
Create the CreaCir in run, but don't put it in the list:
class Ventana:
def __init__(self, Ven_Tam= (700, 500)):
pg.init()
self.ven_tam = Ven_Tam
self.ven = pg.display.set_caption("Linea")
self.ven = pg.display.set_mode(self.ven_tam)
self.ven.fill(pg.Color('#404040'))
self.figs = []
self.reloj = pg.time.Clock()
def check_events(self):
# [...]
def run(self):
cirCreater = CreaCir(self.figs)
while True:
self.check_events()
cirCreater.update()
for fig in self.figs:
fig.dibujar(self.ven)
self.reloj.tick(30)
To detect the collision of 2 circles, you need to calculate the distance between the centers of the circles and check if the distance is greater than the sum of the radii of the circles. The 3rd argument of pygame.draw.circle is the center of the circle, but not the top left of the bounding box of the circle:
pg.draw.circle(ventana, "white", (self.x, self.y), self.radio, 1)
pg.draw.circle(ventana, "white", (self.cx, self.cy), self.radio, 1)
Complete example:
import pygame as pg
import math, random
class Circulo:
def __init__(self, x, y, r):
self.x, self.y = x, y
self.radio = r
self.cx, self.cy = x+r, y+r
def dibujar(self, ventana):
pg.draw.circle(ventana, "white", (self.cx, self.cy), self.radio, 1)
def colisionC(self, c2):
dx = self.cx - c2.cx
dy = self.cy - c2.cy
return self.radio + c2.radio > math.sqrt(dx*dx + dy*dy)
class CreaCir:
def __init__(self, figs):
self.figs = figs
def update(self):
if len(self.figs) < 100:
choca = False
r = random.randint(5, 104)
x = random.randint(0, 700 - r*2)
y = random.randint(0, 500 - r*2)
creOne = Circulo(x, y, r)
for fig in self.figs:
choca = creOne.colisionC(fig)
if choca == True:
break
if choca == False:
self.figs.append(creOne)
class Ventana:
def __init__(self, Ven_Tam= (700, 500)):
pg.init()
self.ven_tam = Ven_Tam
self.ven = pg.display.set_caption("Linea")
self.ven = pg.display.set_mode(self.ven_tam)
self.figs = []
self.reloj = pg.time.Clock()
def check_events(self):
for event in pg.event.get():
if event.type == pg.QUIT or (event.type == pg.KEYDOWN and event.key == pg.K_ESCAPE):
quit()
def run(self):
cirCreater = CreaCir(self.figs)
while True:
self.check_events()
cirCreater.update()
self.ven.fill(pg.Color('#404040'))
for fig in self.figs:
fig.dibujar(self.ven)
pg.display.flip()
self.reloj.tick(30)
if __name__ == '__main__':
ven = Ventana()
ven.run()

Related

Conway's Game of Life Gliders break after a few generations

So I tried creating Conway's game of life in python with pygame. I made this without watching any tutorials, which is probably why it is so broken. It seems to be working fine, but when I creates a glider it seems to just break after a few generations. I looked at some other posts about my problem and added their solutions but that didn't make it work either. I know this is a lot to ask for, but can someone at least identify the problem.
Here is my code. I expected the glider to function as do they are supposed to, but it ended up just breaking in a few generations
Code:
main.py:
from utils import *
from grid import Grid
running = True
t = Grid(30)
while running:
pygame.display.set_caption(f'Conways Game of Life <Gen {t.generations}>')
clock.tick(200)
screen.fill(background_colour)
if not t.started:
t.EditMode()
else:
t.Update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.display.flip()`
grid.py:
import cell
from utils import *
class Grid:
def __init__(self, size):
self.cells = []
self.cellSize = size
self.generations = 0
self.tick = 1
self.started = False
self.GenerateGrid()
def GenerateGrid(self):
x, y = 0, 0
while y < screen.get_height():
while x < screen.get_width():
c = cell.Cell(self, (x,y), self.cellSize)
self.cells.append(c)
x+=self.cellSize
x = 0
y+=self.cellSize
def EditMode(self):
self.Draw()
if self.started:
return
for cell in self.cells:
if pygame.mouse.get_pressed()[0]:
if cell.rect.collidepoint(pygame.mouse.get_pos()):
cell.state = 1
if pygame.mouse.get_pressed()[2]:
if cell.rect.collidepoint(pygame.mouse.get_pos()):
cell.state = 0
keys = pygame.key.get_pressed()
if keys[pygame.K_RETURN]:
self.started = True
def Draw(self):
for cell in self.cells:
cell.Draw()
def Update(self):
self.Draw()
self.tick -= 0.05
if self.tick < 0:
for cell in self.cells:
cell.UpdateState()
for cell in self.cells:
cell.state = cell.nextState
self.tick = 1
self.generations+=1
cell.py
from utils import *
class Cell:
def __init__(self, grid, position:tuple, size):
self.grid = grid
self.size = size
self.position = pygame.Vector2(position[0], position[1])
self.rect = pygame.Rect(self.position.x, self.position.y, self.size, self.size)
self.state = 0
self.nextState = self.state
def Draw(self):
pygame.draw.rect(screen, (0,0,0), self.rect)
if self.state == 0:
pygame.draw.rect(screen, (23,23,23), (self.position.x+4, self.position.y+4, self.size-4, self.size-4))
else:
pygame.draw.rect(screen, (255,255,255), (self.position.x+4, self.position.y+4, self.size-4, self.size-4))
def UpdateState(self):
rect = pygame.Rect(self.position.x-self.size, self.position.y-self.size, self.size*3, self.size*3)
pygame.draw.rect(screen, (0,0,0), rect)
targetCells = []
for c in self.grid.cells:
if rect.colliderect(c.rect):
targetCells.append(c)
livingAmt = 0
for c in targetCells:
if c.rect.x == self.rect.x and c.rect.y == self.rect.y:
continue
if c.state == 1:
livingAmt+=1
if self.state == 1:
if livingAmt > 3 or livingAmt <2:
self.nextState = 0
if self.state ==0:
if livingAmt == 3:
self.nextState =1
utils.py
import pygame
background_colour = (23, 23, 23)
screen = pygame.display.set_mode((900, 900))
clock = pygame.time.Clock()
running = True
Your function UpdateState both counts a cell's neighbors and updates the cell's state. Since you call that function in a loop, both are done together, which does not work, as explained here. You must split the "count" phase from the "update state" phase.

Why does this variable change value despite not being referenced?

I need to create a base rectangle, and the blitted rectangle (default_rect and rect) for both scaling and scrolling purposes. I'm trying to change the y value of the RECT individually, but it somehow changes the value of default_rect also? I have no idea why. Perhaps the issue is coming from somewhere else. I have tried to create a minimum reproducible example to show what I'm talking about.
class Element(pg.sprite.Sprite):
def __init__(self, img, x, y, placement="center"):
super().__init__()
self.image = img
if placement == "topright":
self.rect = self.image.get_rect(topright=(x, y))
if placement == "center":
self.rect = self.image.get_rect(center=(x, y))
self.default_rect = self.rect
print("Test")
def update_rect(self, y_offset):
self.rect.centery = self.default_rect.centery + y_offset
When calling this update_rect() function, I see no reason why the value of self.default_rect.centery should be affected at all. This is the only place I reference default_rect.centery. I do not think that the issue is coming from the __init__ running multiple times because "Test" is only printed when initalising.
Rest of the minimum reproducible example. The rectangle continuously increases it's y position to -1,000,000 in seconds (without fps limit).
import pygame as pg
pg.init()
screen_width, screen_height = 800, 600
screen = pg.display.set_mode((screen_width, screen_height))
grey = (150, 150, 150)
dark_grey = (60, 60, 60)
class Element(pg.sprite.Sprite):
def __init__(self, img, x, y, placement="center"):
super().__init__()
self.image = img
if placement == "topright":
self.rect = self.image.get_rect(topright=(x, y))
if placement == "center":
self.rect = self.image.get_rect(center=(x, y))
self.default_rect = self.rect
print("Test")
def update_rect(self, y_offset):
self.rect.centery = self.default_rect.centery + y_offset
class ScrollBar(Element):
def __init__(self, x, y, total_bar_w, total_bar_h, total_h):
img = pg.Surface((total_bar_w, total_bar_h))
img.fill(dark_grey)
super().__init__(img, x, y, "topright")
bar_w = 0.98*total_bar_w
bar_h = (total_bar_h / total_h) * total_bar_h
bar_img = pg.Surface((bar_w, bar_h))
bar_img.fill(grey)
self.bar = Element(bar_img, x, y, "topright")
self.total_h = total_h
self.ratio = self.total_h / self.rect.h
self.offset = 0
self.y_offset = 0
self.pressed = False
self.active = False
def update(self):
pos = pg.mouse.get_pos()
click = pg.mouse.get_pressed()[0]
# Check if the slider bar was pressed
if click and self.rect.collidepoint(pos):
self.active = True
# Checking if mouse was released or mouse left the allowed zone
if not click or abs(pos[0] - self.rect.midleft[0]) > self.rect.w*3:
self.active = False
if self.active:
self.bar.rect.centery = pos[1]
if self.bar.rect.top < 0:
self.bar.rect.top = 0
if self.bar.rect.bottom > self.rect.top + self.rect.h:
self.bar.rect.bottom = self.rect.top + self.rect.h
# Calculate y offset for elements. Multiply by negative
# to allow us to add the offset rather than subtract
self.y_offset = (self.bar.rect.centery - self.bar.rect.h / 2) * -self.ratio
def draw(self):
screen.blit(self.image, (self.rect.x, self.rect.y))
screen.blit(self.bar.image, (self.bar.rect.x, self.bar.rect.y))
class Button(Element):
def __init__(self, x, y, w, h):
super().__init__(pg.Surface((w, h)), x, y, "center")
self.clicked = False
def update(self):
self.update_rect(scroll_bar.y_offset)
action = False
if self.rect.collidepoint(pg.mouse.get_pos()):
if pg.mouse.get_pressed()[0] and not self.clicked:
self.clicked = True
action = True
if not pg.mouse.get_pressed()[0]:
self.clicked = False
return action
def draw(self):
pg.draw.rect(screen, "blue", self.rect)
button1 = Button(400, 100, 200, 150)
button2 = Button(400, 300, 200, 150)
button3 = Button(400, 500, 200, 150)
buttons = [button1, button2, button3]
total_height = screen_height * 2
scroll_bar = ScrollBar(screen_width, 0, 0.05 * screen_width, screen_height, total_height)
run = True
while run:
screen.fill("white")
for button in buttons:
button.draw()
if button.update():
print("Button's y value is: " + str(button.rect.y))
scroll_bar.update()
scroll_bar.draw()
for e in pg.event.get():
if e.type == pg.QUIT:
run = False
if e.type == pg.KEYDOWN:
if e.key == pg.K_SPACE:
print(f"{button1.rect.y} / {button2.rect.y} / {button3.rect.y}")
if e.key == pg.K_r:
print(scroll_bar.y_offset)
pg.display.update()
When you assign self.default_rect = self.rect in __init__() both variables are references to the same object. So later in update_rect() when you change self.rect.centery, the change is reflected in self.default_rect because they both refer to the same object.
To understand how this works, check out the excelent talk by Ned Batchelder about names and values.

Pygame gfxdraw program [duplicate]

This question already has answers here:
Create trails of particles for the bullets
(1 answer)
Pygame change particle color
(1 answer)
Closed 5 months ago.
I am a beginner with pygame. I want to include a few "Emitter" classes to "Particle" class to show points. It doesn't work and I don't know how to fix it. I think the problem is with gfxdraw. In the "Emitter" class, it initializes the system window. This can also be a problem. I don't know how to transfer this to the "Particle" class. Would it help at all? I used many combinations for repair. Nothing works. Please help. Does anyone have any idea?
import random
import sys
import pygame
from pygame.locals import *
import pygame.gfxdraw
class ParticleSystem:
def __init__(self, id, pos, a,b, width, height, radius, color):
self.id = id
self.width = width
self.height = height
self.radius = radius
self.color = color
self.g = 9.81
self.pos = [random.randint(a,b), 0]
self.enabled = True
self.df = 0
def update(self, time, collision):
if self.enabled:
v = 1 / float(time)
if not self.collision_detect(collision):
self.pos[1] += self.g*v
else:
self.enabled = False
if self.df != 0:
F = (self.g*v)/9
if self.df < 0:
F = -F
self.pos[0] += F
self.df -= F
def collision_detect(self, collision):
x = int(self.pos[0])
y = self.pos[1]
r = self.radius
points = collision[x-r:x+r]
for p in points:
if y + r >= p:
for i in range(x-r, x+r):
if i >= 0 and i < self.width:
collision[i] = y
return True
if self.pos[1] >= self.height:
return True
else:
return False
def draw(self, surface):
pygame.gfxdraw.filled_circle(surface, int(self.pos[0]), int(self.pos[1]), self.radius, self.color)
pygame.gfxdraw.aacircle(surface, int(self.pos[0]), int(self.pos[1]), self.radius, self.color)
class Emitter:
def __init__(self, a, b, height, width):
self.a = a
self.b = b
self.timer = 60
self.width = width
self.height = height
self.color = (255, 255, 255)
self.background_color = (0, 0, 0)
self.pos = [0,0]
self.particles = []
self.counter = 0
self.freq = 5
self.size = 4
self.collision = [height] * width
self.df_c = 1
self.df_f = 100
self.begin()
def begin(self):
self.screen = pygame.display.set_mode((self.width, self.height))
self.clock = pygame.time.Clock()
while 1:
time = self.clock.get_time()
self.update(time)
self.clock.tick(self.timer)
self.render(time)
def update(self, time):
if self.counter > self.freq:
self.counter = 0
particle = ParticleSystem(len(self.particles), self.pos, self.a, self.b, self.width, self.height, self.size, self.color)
self.particles.append(particle)
else:
self.counter += 1
df_c = random.randint(0, 100)
df_f = 0
if df_c <= self.df_c:
df_f = random.randint(-self.df_f, self.df_f)
for part in self.particles:
if part.enabled:
if df_f != 0:
part.df = df_f
part.update(time, self.collision)
def render(self, time):
surface = pygame.Surface(self.screen.get_size())
surface.convert()
surface.fill(self.background_color)
for part in self.particles:
part.draw(surface)
self.screen.blit(surface, (0, 0))
pygame.display.flip()
class Particle:
def __init__(self, width, height, caption):
self.width = width
self.height = height
self.caption = caption
self.initialization()
def initialization(self):
pygame.init()
pygame.display.set_caption(self.caption)
#Emitter(0, self.width, self.height, self.width)
Emitter(0, 125, self.height, self.width)
Emitter(200, 500, self.height, self.width) #how to show the second Emitter
self.input(pygame.event.get())
def input(self, events):
for event in events:
if event.type == pygame.QUIT:
sys.exit(0)
elif event.type == KEYDOWN:
if event.key == K_ESCAPE:
sys.exit(0)
if __name__ == "__main__":
particle = Particle(800, 600, "Particle System - Christmas Time")

Pygame only advances on keypress

I imagine this is a simple fix and have seen similar questions, but this is really frustrating me. Basically when you run the game, it only advances the simulation on a keypress, and not at a set framerate.
https://pastebin.com/aP6LsMMA
The main code is:
pg.init()
clock = pg.time.Clock()
FPS = 10
# ...
Game = Control()
while not Game.done:
Game.main_loop()
pg.display.update()
clock.tick(FPS)
pg.quit()
and the event handler method - within the Control class - is:
def event_handler(self):
for event in pg.event.get():
if event.type == pg.QUIT:
self.done = True
elif event.type == pg.KEYDOWN:
self.scene.process_event(event)
The weird thing to me is that, at the bottom of the pastebin, is my old testing code that is not done with classes for Scenes/Control. However, to my eye it should work exactly the same. I've tried putting in the clock both in and out of the Control class to no avail.
Any help (and general tips!) greatly appreciated.
Thanks
process_event() should only change variables which depend on events but it shouldn't update other values which should be updated in every frame. You have to move some elements to new method update() and execute it in every loop.
More or less
class Scene:
def process_event(self, event):
pass
def update(self):
pass
class GamePlayState(Scene):
def process_event(self, event):
self.snake.get_key(event)
def update(self):
self.snake.update()
self.snake.food_check(self.apple)
self.snake.collision_check()
if self.snake.alive == False:
print("GAME OVER")
print(self.snake.points)
self.done = True
class Control:
def update(self):
self.scene.update()
def main_loop(self):
self.event_handler()
self.update()
self.scene_checker()
self.draw()
Full working code
import pygame as pg
import sys
import random
import queue
# TODO: Walls, queue for keypress, scene stuff, 2 player, difficulty(?)
""" ######################
PREAMBLE
###################### """
""" Dictionaries for direction/velocity mapping - stolen from https://github.com/Mekire """
DIRECT_DICT = {"left" : (-1, 0), "right" : (1, 0),
"up" : (0,-1), "down" : (0, 1)}
KEY_MAPPING = {pg.K_LEFT : "left", pg.K_RIGHT : "right",
pg.K_UP : "up", pg.K_DOWN : "down"}
OPPOSITES = {"left" : "right", "right" : "left",
"up" : "down", "down" : "up"}
""" Colour Mapping """
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
DARK_GREY = (70, 70, 70)
GREY = (211, 211, 211)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
COLOUR_MAP = {"snake": GREEN, "apple": RED, "wall": BLACK, "surface": GREY, "background": DARK_GREY }
""" ################
CLASSES
################ """
""" ####################### Object Classes ########################## """
class Square:
""" All other objects in the game will be built up from this """
def __init__(self, pos, colour, length):
self.xi, self.yi = pos # i for index, p for pixel
self.colour = colour
self.length = length
def display(self):
xp, yp = self.sq_to_pixs(self.xi, self.yi) # (x = left side, y = top edge)
pg.draw.rect(screen, self.colour, (xp, yp, self.length, self.length), 0)
def sq_to_pixs(self, x, y):
# Converts index of square to pixel coords
px = (x+1)*(2*MARGIN + SQUARE_SIZE) - MARGIN - SQUARE_SIZE
py = (y+1)*(2*MARGIN + SQUARE_SIZE) - MARGIN
return (px, py)
def index_coords(self): # TODO - remove for direct ref?
return (self.xi, self.yi)
class Arena:
""" A grid within which the game takes place """
def __init__(self, size, square_length, colour):
self.size = size # i.e. number of squares = size**2 for square arena
self.length = square_length # i.e. per square dimension
self.colour = colour
self.squares = [ [] for i in range(self.size) ]
for y in range(self.size):
for x in range(self.size):
self.squares[y].append(Square((x,y), self.colour, self.length))
def display(self):
for y in self.squares:
for square in y:
square.display()
class Snake:
""" Class for the agent(s) """
def __init__(self, pos, colour, square_length):
self.xi, self.yi = pos
self.colour = colour
self.size = 3
self.length = square_length
self.direction = "right"
self.direction_queue = queue.Queue(4) # TODO
self.points = 0
self.growing = False
self.alive = True
self.squares = []
for x in range(self.size): # horizontal initial orientation
self.squares.append(Square((self.xi - x, self.yi), self.colour, self.length))
def display(self):
for square in self.squares:
square.display()
def food_check(self, apple):
if self.squares[0].index_coords() == apple.square.index_coords():
self.growing = True
self.points += apple.points_value
apple.respawn([self])
def collision_check(self, walls = None):
xh, yh = self.squares[0].index_coords()
body = self.squares[-1:0:-1] # going backwards thru array as forwards [0:-1:1] didnt work...
def _collide(obstacles):
for sq in obstacles:
_x, _y = sq.index_coords()
if (_x == xh) and (_y == yh):
self.alive = False
_collide(body)
if walls is not None:
_collide(walls)
def update(self):
# Add new head based on velocity and old head
velocity = DIRECT_DICT[self.direction]
head_coords = [ (self.squares[0].index_coords()[i] + velocity[i]) for i in (0,1) ]
# Wrap around screen if reach the end
for i in (0, 1):
if head_coords[i] < 0:
head_coords[i] = SQUARES_PER_ARENA_SIDE - 1
elif head_coords[i] > SQUARES_PER_ARENA_SIDE - 1:
head_coords[i] = 0
self.squares.insert(0, Square(head_coords, self.colour, self.length))
if self.growing:
self.growing = False
else:
del self.squares[-1]
"""
def queue_key_press(self, key):
for keys in KEY_MAPPING:
if key in keys:
try:
self.direction_queue.put(KEY_MAPPING[keys], block=False)
break
except queue.Full:
pass
"""
class Player(Snake):
""" Human controlled snake via arrow keys """
def __init__(self, pos, colour, size):
Snake.__init__(self, pos, colour, size)
def get_key(self, event):
if event.type == pg.KEYDOWN and event.key in KEY_MAPPING:
new_direction = KEY_MAPPING[event.key]
if new_direction != OPPOSITES[self.direction]:
self.direction = new_direction
class Apple:
""" Food our (veggie) snake is greedily after """
def __init__(self, colour, length, points_value, snake):
self.colour = colour
self.length = length
self.xi, self.yi = self._rand_coords()
self.points_value = points_value
self.square = Square((self.xi, self.yi), self.colour, self.length)
def _rand_coords(self):
rand_num = lambda x: random.randint(0, x)
_x = rand_num(SQUARES_PER_ARENA_SIDE-1)
_y = rand_num(SQUARES_PER_ARENA_SIDE-1)
return _x, _y
def respawn(self, obstacles):
_x, _y = self._rand_coords()
for ob in obstacles:
for sq in ob.squares:
while sq.index_coords() == (_x, _y):
_x, _y = self._rand_coords()
self.square.xi, self.square.yi = _x, _y
def display(self):
self.square.display()
""" ################ SCENES ####################### """
class Scene:
""" Overload most of this - barebones structure
A bit pointless in current state but easily expanded """
def __init__(self):
self.done = False
def when_activated(self):
pass
def reset(self):
self.done = False
def render(self):
pass
def process_event(self, event):
pass
def update(self):
pass
class StartUp(Scene):
def __init__(self):
Scene.__init__(self)
def render(self):
# test placeholder
pass
def when_activated(self):
print("Press any key to continue")
def process_event(self, event):
if event.type == pg.KEYDOWN:
self.done = True
class GamePlayState(Scene):
def __init__(self):
Scene.__init__(self)
self.arena = Arena(SQUARES_PER_ARENA_SIDE, SQUARE_SIZE, COLOUR_MAP["surface"])
self.snake = Player(SNAKE_START, COLOUR_MAP["snake"], SQUARE_SIZE)
self.apple = Apple(COLOUR_MAP["apple"], SQUARE_SIZE, 1, self.snake)
self.font = pg.font.SysFont("courier new", 50)
def render(self):
screen.fill(COLOUR_MAP["background"])
self.arena.display()
self.apple.display()
self.snake.display()
text = self.font.render(str(self.snake.points), True, [255,255,255])
screen.blit(text, (500, 400))
def process_event(self, event):
self.snake.get_key(event)
def update(self):
self.snake.update()
self.snake.food_check(self.apple)
self.snake.collision_check()
if self.snake.alive == False:
print("GAME OVER")
print(self.snake.points)
self.done = True
""" ################## CONTROL CLASS #########################"""
class Control:
def __init__(self):
#self.clock = pg.time.Clock()
#self.fps = FPS
self.done = False
self.scene_array = [StartUp(), GamePlayState()]
self.scene_index = 0 # dirty way whilst dict method needs tinkering
#self.scene_dict = {"START": StartUp(), "GAME": GamePlayState()} #TODO
self.scene = self.scene_array[self.scene_index]
#self.scene = self.scene_dict["START"]
self.scene.when_activated()
def event_handler(self):
for event in pg.event.get():
if event.type == pg.QUIT:
self.done = True
elif event.type == pg.KEYDOWN:
self.scene.process_event(event)
def scene_checker(self):
if self.scene.done:
self.scene.reset() # for reuse - TODO
self.scene_index = (self.scene_index + 1) % len(self.scene_array)
self.scene = self.scene_array[self.scene_index]
self.scene.when_activated()
#self.scene = self.scene_dict[self.scene.next]
def update(self):
self.scene.update()
def draw(self):
self.scene.render()
def main_loop(self):
self.event_handler()
self.update()
self.scene_checker()
self.draw()
""" ################ RUN GAME ################ """
""" Game paramaters """
SQUARE_SIZE = 20 # pixels
SQUARES_PER_ARENA_SIDE = 20 # squares
MARGIN = 2 # pixels
SNAKE_START = (int(SQUARES_PER_ARENA_SIDE/2), int(SQUARES_PER_ARENA_SIDE/2)) # square coords
pg.init()
clock = pg.time.Clock()
# Square.display() and a few others need a direct reference to "screen" TODO implement better
w, h = 620, 620
SCREEN_SIZE = [w, h]
FPS = 10
screen = pg.display.set_mode(SCREEN_SIZE)
Game = Control()
while not Game.done:
Game.main_loop()
pg.display.update()
clock.tick(FPS)
pg.quit()

How to add afterimages in pygame?

Since character movement is grid based, characters look a bit odd when going from square to square as they just appear from one square onto another. To make the movement feel more natural, I wanted to add "afterimages" so that there would be a simulation of smooth movement.
Demonstrational image:
Since my code has characters moving directly onto the next square, I don't know how to blit sprites in between.
if IDO.get_key(pygame.K_RIGHT):
if PhaseFocus == 0 or PhaseFocus == 2:
Reticlex +=1
if Currently_Selected != 0 and Currently_Selected.Phase == 2:
if Currently_Selected.x != Reticlex:
Currently_Selected.x = Reticlex
if Currently_Selected.x != Reticley:
Currently_Selected.y = Reticley
if IDO.get_key(pygame.K_LEFT):
if PhaseFocus == 0 or PhaseFocus == 2:
Reticlex -=1
if Currently_Selected != 0 and Currently_Selected.Phase == 2:
if Currently_Selected.x != Reticlex:
Currently_Selected.x = Reticlex
if Currently_Selected.x != Reticley:
Currently_Selected.y = Reticley
When the currently selected character is in Phase 2 (carried around) they should have these afterimages.
Let's see how we can do this.
Step 1: Basic setup
We start with an "empty" pygame game, like this:
import pygame
def main():
screen = pygame.display.set_mode((640, 480))
clock = pygame.time.Clock()
while True:
events = pygame.event.get()
for e in events:
if e.type == pygame.QUIT:
return
screen.fill((30, 30, 30))
pygame.display.flip()
clock.tick(60)
if __name__ == '__main__':
main()
We have a Clock, a single game loop and handle the QUIT event. I always store the events from event.get() in a variable in case I want to iterate over them again, e.g. when a Sprite wants to listen for an event. Always call event.get() only once per frame!
Step 2: A grid
We want a grid based game, so let's draw a grid. Also, we store a bunch of Rects in a list so it will be easy for us to lookup the screen coordinates of an object. We want to center objects in their tile, so using the Rect class will do the dirty work for us.
import pygame
TILESIZE = 32
GRID_W, GRID_H = (20, 15)
def create_grid():
surf = pygame.Surface((TILESIZE * GRID_W, TILESIZE * GRID_H))
surf.set_colorkey((2, 2, 2))
surf.fill((2, 2, 2))
grid = []
for y in range(GRID_H):
line = []
for x in range(GRID_W):
r = pygame.Rect(x * TILESIZE, y * TILESIZE, TILESIZE, TILESIZE)
line.append(r)
pygame.draw.rect(surf, pygame.Color('grey'), r, 1)
grid.append(line)
return grid, surf
def main():
screen = pygame.display.set_mode((TILESIZE * GRID_W, TILESIZE * GRID_H))
clock = pygame.time.Clock()
grid, grid_surf = create_grid()
while True:
events = pygame.event.get()
for e in events:
if e.type == pygame.QUIT:
return
screen.fill((30, 30, 30))
screen.blit(grid_surf, (0, 0))
pygame.display.flip()
clock.tick(60)
Step 3: Something's moving on the grid
We now create an actor that travels on this grid. In this case it's a simple Sprite that moves every second.
import pygame
import random
TILESIZE = 32
GRID_W, GRID_H = (20, 15)
LOOKUP = None
class Actor(pygame.sprite.Sprite):
def __init__(self, grid_pos):
super().__init__()
self.image = pygame.Surface((TILESIZE // 2, TILESIZE // 2))
self.rect = self.image.get_rect()
self.pos = pygame.Vector2()
self.update_pos(grid_pos)
self.image.fill(pygame.Color('dodgerblue'))
self.timeout = 1000
def update_pos(self, grid_pos):
self.grid_pos = grid_pos
self.rect.center = get_grid_rect(grid_pos).center
self.pos = pygame.Vector2(self.rect.topleft)
def move_random(self):
d = random.choice([-1, 1])
x, y = self.grid_pos
if random.randint(0, 2):
x += d
else:
y += d
self.update_pos((x, y))
def update(self, events, dt):
self.timeout -= dt
if self.timeout <= 0:
self.timeout = 1000
self.move_random()
def get_grid_rect(pos):
x, y = pos
return LOOKUP[y][x]
def create_grid():
surf = pygame.Surface((TILESIZE * GRID_W, TILESIZE * GRID_H))
surf.set_colorkey((2, 2, 2))
surf.fill((2, 2, 2))
grid = []
for y in range(GRID_H):
line = []
for x in range(GRID_W):
r = pygame.Rect(x * TILESIZE, y * TILESIZE, TILESIZE, TILESIZE)
line.append(r)
pygame.draw.rect(surf, pygame.Color('grey'), r, 1)
grid.append(line)
return grid, surf
def main():
screen = pygame.display.set_mode((TILESIZE * GRID_W, TILESIZE * GRID_H))
dt, clock = 0, pygame.time.Clock()
grid, grid_surf = create_grid()
global LOOKUP
LOOKUP = grid
sprites = pygame.sprite.Group(Actor((9, 6)))
while True:
events = pygame.event.get()
for e in events:
if e.type == pygame.QUIT:
return
sprites.update(events, dt)
screen.fill((30, 30, 30))
screen.blit(grid_surf, (0, 0))
sprites.draw(screen)
pygame.display.flip()
dt = clock.tick(60)
if __name__ == '__main__':
main()
Step 4: Smooth movement
Instead of always drawing the Actor that the center of the tiles, we set a target_grid_pos when we want to move. Each frame, we move the Actor a little bit until we reached our target tile. We use pygame's Vector2 class and it's lerp and distance_to methods.
import pygame
import random
TILESIZE = 32
GRID_W, GRID_H = (20, 15)
LOOKUP = None
class Actor(pygame.sprite.Sprite):
def __init__(self, grid_pos):
super().__init__()
self.image = pygame.Surface((TILESIZE // 2, TILESIZE // 2))
self.rect = self.image.get_rect()
self.pos = pygame.Vector2()
self.update_pos(grid_pos)
self.image.fill(pygame.Color('dodgerblue'))
self.timeout = 1000
def update_pos(self, grid_pos):#
self.target_pos = None
self.target_grid_pos = None
self.grid_pos = grid_pos
self.rect.center = get_grid_rect(grid_pos).center
self.pos = pygame.Vector2(self.rect.center)
def move_random(self):
d = random.choice([-1, 1])
x, y = self.grid_pos
if random.randint(0, 2):
x += d
else:
y += d
self.target_pos = pygame.Vector2(get_grid_rect((x, y)).center)
self.target_grid_pos = (x, y)
def update(self, events, dt):
self.timeout -= dt
if self.timeout <= 0:
self.timeout = 1000
self.move_random()
if self.target_grid_pos:
self.pos = self.pos.lerp(self.target_pos, 0.1)
if self.pos.distance_to(self.target_pos) < 1:
self.update_pos(self.target_grid_pos)
self.rect.center = self.pos
def get_grid_rect(pos):
x, y = pos
return LOOKUP[y][x]
def create_grid():
surf = pygame.Surface((TILESIZE * GRID_W, TILESIZE * GRID_H))
surf.set_colorkey((2, 2, 2))
surf.fill((2, 2, 2))
grid = []
for y in range(GRID_H):
line = []
for x in range(GRID_W):
r = pygame.Rect(x * TILESIZE, y * TILESIZE, TILESIZE, TILESIZE)
line.append(r)
pygame.draw.rect(surf, pygame.Color('grey'), r, 1)
grid.append(line)
return grid, surf
def main():
screen = pygame.display.set_mode((TILESIZE * GRID_W, TILESIZE * GRID_H))
dt, clock = 0, pygame.time.Clock()
grid, grid_surf = create_grid()
global LOOKUP
LOOKUP = grid
sprites = pygame.sprite.Group(Actor((9, 6)))
while True:
events = pygame.event.get()
for e in events:
if e.type == pygame.QUIT:
return
sprites.update(events, dt)
screen.fill((30, 30, 30))
screen.blit(grid_surf, (0, 0))
sprites.draw(screen)
pygame.display.flip()
dt = clock.tick(60)
if __name__ == '__main__':
main()
Step 5: Adding the effect
Every 300 ms, we create a copy of the Actor's image, blit it at the Actor's position, and make sure to delete it after 200ms. In a real game, you probably want to cache the images or use pre-rendered ones.
I switched the Group for LayeredUpdates so we can make sure the original images is always drawn above the "shadows".
I also added an image (from rltiles) instead of a simple rect so it looks nicer in this demo.
import pygame
import random
import gzip
import base64
TILESIZE = 64
GRID_W, GRID_H = (10, 7)
LOOKUP = None
class Shadow(pygame.sprite.Sprite):
def __init__(self, source):
super().__init__()
self._layer = 5
self.image = source.image.copy().convert_alpha()
self.image.fill((0, 0, 200, 100), special_flags=pygame.BLEND_ADD)
self.rect = source.rect.copy()
self.timeout = 200
def update(self, events, dt):
self.timeout -= dt
if self.timeout <= 0:
self.kill()
class Actor(pygame.sprite.Sprite):
def __init__(self, grid_pos):
super().__init__()
self._layer = 10
data, size = gzip.decompress(base64.b64decode(HYDRA)), (64, 64)
self.image = pygame.image.fromstring(data, size, "RGB")
self.image.set_colorkey((71, 108, 108))
self.rect = self.image.get_rect()
self.pos = pygame.Vector2()
self.update_pos(grid_pos)
self.timeout = 1000
self.shadow_timeout = 100
def update_pos(self, grid_pos):#
self.target_pos = None
self.target_grid_pos = None
self.grid_pos = grid_pos
self.rect.center = get_grid_rect(grid_pos).center
self.pos = pygame.Vector2(self.rect.center)
def move_random(self):
d = random.choice([-1, 1])
x, y = self.grid_pos
if random.randint(0, 2):
x += d
else:
y += d
self.target_pos = pygame.Vector2(get_grid_rect((x, y)).center)
self.target_grid_pos = (x, y)
def update(self, events, dt):
self.timeout -= dt
if self.timeout <= 0:
self.timeout = 1000
self.move_random()
if self.target_grid_pos:
self.shadow_timeout -= dt
if self.shadow_timeout <= 0:
self.shadow_timeout = 100
self.groups()[0].add(Shadow(self))
self.pos = self.pos.lerp(self.target_pos, 0.1)
if self.pos.distance_to(self.target_pos) < 1:
self.update_pos(self.target_grid_pos)
self.rect.center = self.pos
def get_grid_rect(pos):
x, y = pos
return LOOKUP[y][x]
def create_grid():
surf = pygame.Surface((TILESIZE * GRID_W, TILESIZE * GRID_H))
surf.set_colorkey((2, 2, 2))
surf.fill((2, 2, 2))
grid = []
for y in range(GRID_H):
line = []
for x in range(GRID_W):
r = pygame.Rect(x * TILESIZE, y * TILESIZE, TILESIZE, TILESIZE)
line.append(r)
pygame.draw.rect(surf, pygame.Color('grey'), r, 1)
grid.append(line)
return grid, surf
def main():
screen = pygame.display.set_mode((TILESIZE * GRID_W, TILESIZE * GRID_H))
dt, clock = 0, pygame.time.Clock()
grid, grid_surf = create_grid()
global LOOKUP
LOOKUP = grid
sprites = pygame.sprite.LayeredUpdates(Actor((4, 3)))
while True:
events = pygame.event.get()
for e in events:
if e.type == pygame.QUIT:
return
sprites.update(events, dt)
screen.fill((30, 30, 30))
screen.blit(grid_surf, (0, 0))
sprites.draw(screen)
pygame.display.flip()
dt = clock.tick(60)
HYDRA = 'H4sIAEVFLF0C/+16Z2xk15Xmea8CK5LFKrJYOeecc85VJItkkaxizjl0ZOeWWq2WrNCSW61kW5IlB8lKli3ZLdnWjlfQAl57vTuDhWeA3QHs/THwzGCwwGLmhweY/bXnk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