Here's how it looks.
It works as should so far, with sprites bouncing around within a box and random speeds as well.
The amount of red pixels are based on a variable ex "team1_infantry" and likewise with team2_* & etc.
When started 45 seconds will countdown, and then which side that has the most sprites will win.
This is the logic so far.
Code: Select all
def repulsor_update(st):
global team1_infantry
# For each sprite in team 1...
for i in repulsor_sprites:
speed_clamped_y = i.team1_i_speed_y * .01
speed_clamped_x = i.team1_i_speed_x * .01
i.x += i.bdx * speed_clamped_x
i.y += i.bdy * speed_clamped_y
top = 120 - 5 / 2
if i.y < top:
i.y = top + (i.y - top)
i.bdy = -i.bdy
bottom = 520 - 5 / 2
if i.y > bottom:
i.y = bottom - (i.y - bottom)
i.bdy = -i.bdy
left = 175 - 5 / 2
if i.x < left:
i.x = left + (i.x - left)
i.bdx = -i.bdx
right = 905 - 5 / 2
if i.x > right:
i.x = right - (i.x - right)
i.bdx = -i.bdx
## FOR OTHER TEAM
for e in repulsor_sprites2:
speed_clamped_y = e.team2_i_speed_y * .01
speed_clamped_x = e.team2_i_speed_x * .01
e.x += e.bdx * speed_clamped_x
e.y += e.bdy * speed_clamped_y
top = 120 - 5 / 2
if e.y < top:
e.y = top + (e.y - top)
e.bdy = -e.bdy
bottom = 520 - 5 / 2
if e.y > bottom:
e.y = bottom - (e.y - bottom)
e.bdy = -e.bdy
left = 175 - 5 / 2
if e.x < left:
e.x = left + (e.x - left)
e.bdx = -e.bdx
right = 905 - 5 / 2
if e.x > right:
e.x = right - (e.x - right)
e.bdx = -e.bdx
#find coords of e
for i in repulsor_sprites:
if i.x == e.x and i.y == e.y:
team1_infantry -= 1
renpy.sound.play("select.ogg", channel=1)
i.destroy()
return .01
Code: Select all
label testers:
## DELTAS
python:
import pygame
# Create a sprite manager.
repulsor = SpriteManager(update=repulsor_update)
repulsor_sprites = [ ]
repulsor_sprites2 = [ ]
# Ensure we only have one smile displayable.
me = Image("team1_sprite.png")
enemy = Image("team2_sprite.png")
if team1_apcs > 0:
apcs_1 = Image("apc_sprite_t1.png")
if team2_apcs > 0:
apcs_2 = Image("apc_sprite_t2.png")
# Add 400 sprites.
for i in range(team1_infantry):
repulsor_sprites.append(repulsor.create(me))
for i in range(team1_apcs):
repulsor_sprites.append(repulsor.create(apcs_1))
for i in range(team2_infantry):
repulsor_sprites2.append(repulsor.create(enemy))
for i in range(team2_apcs):
repulsor_sprites2.append(repulsor.create(apcs_2))
# Position the 400 sprites.
for i in repulsor_sprites:
i.x = renpy.random.randint(180, 360)
i.y = renpy.random.randint(128, 512)
i.team1_i_speed_x = renpy.random.randint(-300, 300)
i.team1_i_speed_y = renpy.random.randint(-300, 300)
i.bdx = .5
i.bdy = .5
i.rect = pygame.Rect(i.x,i.y,32,32)
for e in repulsor_sprites2:
e.x = renpy.random.randint(720, 900)
e.y = renpy.random.randint(128, 512)
e.team2_i_speed_x = renpy.random.randint(-300, 300)
e.team2_i_speed_y = renpy.random.randint(-300, 300)
e.bdx = .5
e.bdy = .5
e.rect = pygame.Rect(e.x,e.y,32,32)
del me
del i
del e
del enemy
# Add the repulsor to the screen.
show expression repulsor as repulsor
"..."
hide repulsor
# Clean up.
python:
del repulsor
del repulsor_sprites
Code: Select all
for i in repulsor_sprites:
if i.x == e.x and i.y == e.y:
team1_infantry -= 1
i.destroy()