code cleanup

This commit is contained in:
Page Asgardius 2022-01-02 09:57:24 -07:00
parent 3c71322b99
commit 2e867b155b
7 changed files with 27 additions and 57 deletions

View file

@ -1,4 +1,3 @@
# The Red Robot Radio # The Red Robot Radio
A simple game using Pygame library (gamepad required). A simple game using Pygame library (pointer device required).
You control a spaceship with left stick and camera scroll with right stick. Tested with Dualshock 4 on Raspberry Pi and my personal computer with Arch Linux using same gamepad. You control a spaceship with moving computer mouse (or any other input device that can emulate it)
If you are using a different gamepad and/or operating system, you need to edit source code to fit your gamepad commands.

Binary file not shown.

79
r3.py
View file

@ -5,9 +5,6 @@ import time
import datetime import datetime
import platform import platform
import subprocess import subprocess
#introplay = "ffplay -autoexit -window_title Intro intro.ogv"
#process = subprocess.Popen(introplay.split(), stdout=subprocess.PIPE)
#output, error = process.communicate()
pygame.init() pygame.init()
screen = pygame.display.set_mode((800, 480)) screen = pygame.display.set_mode((800, 480))
pygame.display.set_caption('The Red Robot Radio - Virtualx Game Engine') pygame.display.set_caption('The Red Robot Radio - Virtualx Game Engine')
@ -81,6 +78,7 @@ class Wallh(pygame.sprite.Sprite):
pygame.sprite.Sprite.__init__(self) pygame.sprite.Sprite.__init__(self)
self.x = xset self.x = xset
self.y = yset self.y = yset
self.image = pygame.image.load('sprites/wallh.png')
#self.image = pygame.Surface((32, 32)) #self.image = pygame.Surface((32, 32))
#self.image.fill(WHITE) #self.image.fill(WHITE)
#self.rect = self.image.get_rect() # Get rect of some size as 'image'. #self.rect = self.image.get_rect() # Get rect of some size as 'image'.
@ -93,6 +91,7 @@ class Wallv(pygame.sprite.Sprite):
pygame.sprite.Sprite.__init__(self) pygame.sprite.Sprite.__init__(self)
self.x = xset self.x = xset
self.y = yset self.y = yset
self.image = pygame.image.load('sprites/wallv.png')
#self.image = pygame.Surface((32, 32)) #self.image = pygame.Surface((32, 32))
#self.image.fill(WHITE) #self.image.fill(WHITE)
#self.rect = self.image.get_rect() # Get rect of some size as 'image'. #self.rect = self.image.get_rect() # Get rect of some size as 'image'.
@ -209,21 +208,11 @@ while running:
dt = clock.tick(FPS) / 1000 dt = clock.tick(FPS) / 1000
#screen.fill(BLACK) #screen.fill(BLACK)
datetime.datetime.now() datetime.datetime.now()
#bx = 0
#by = 0
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == pygame.QUIT: if event.type == pygame.QUIT:
quit() quit()
elif event.type == pygame.KEYDOWN: elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_w: if event.key == pygame.K_n:
by = -1
elif event.key == pygame.K_s:
by = 1
elif event.key == pygame.K_a:
bx = -1
elif event.key == pygame.K_d:
bx = 1
elif event.key == pygame.K_n:
pygame.mixer.music.stop() pygame.mixer.music.stop()
elif event.key == pygame.K_m: elif event.key == pygame.K_m:
pygame.mixer.music.play(-1) pygame.mixer.music.play(-1)
@ -254,16 +243,8 @@ while running:
start_time = pygame.time.get_ticks() start_time = pygame.time.get_ticks()
elif event.key == pygame.K_ESCAPE: elif event.key == pygame.K_ESCAPE:
quit() quit()
elif event.type == pygame.KEYUP:
if event.key == pygame.K_w:
by = 0
elif event.key == pygame.K_s:
by = 0
elif event.key == pygame.K_a:
bx = 0
elif event.key == pygame.K_d:
bx = 0
if event.type == pygame.MOUSEMOTION: if event.type == pygame.MOUSEMOTION:
#This control camera
pygame.mouse.set_pos([400, 240]) pygame.mouse.set_pos([400, 240])
ax, ay = event.rel ax, ay = event.rel
bx = ax * 20 bx = ax * 20
@ -277,19 +258,23 @@ while running:
if live: if live:
runtime = pygame.time.get_ticks() - start_time runtime = pygame.time.get_ticks() - start_time
if (live & debug == False): if (live & debug == False):
#if pygame.sprite.collide_rect(background, wall3): if pygame.sprite.collide_rect(player, wall3):
# if by < 0: live = False
# by = 0 pygame.mixer.music.stop()
#elif pygame.sprite.collide_rect(background, wall4): csfx.play()
# if by > 0: elif pygame.sprite.collide_rect(player, wall4):
# by = 0 live = False
#if pygame.sprite.collide_rect(background, wall1): pygame.mixer.music.stop()
# if bx < 0: csfx.play()
# bx = 0 if pygame.sprite.collide_rect(player, wall1):
#elif pygame.sprite.collide_rect(background, wall2): live = False
# if bx > 0: pygame.mixer.music.stop()
# bx = 0 csfx.play()
if pygame.sprite.collide_rect(player, css1): elif pygame.sprite.collide_rect(player, wall2):
live = False
pygame.mixer.music.stop()
csfx.play()
elif pygame.sprite.collide_rect(player, css1):
live = False live = False
pygame.mixer.music.stop() pygame.mixer.music.stop()
csfx.play() csfx.play()
@ -310,24 +295,6 @@ while running:
complete = True complete = True
pygame.mixer.music.stop() pygame.mixer.music.stop()
lcfx.play() lcfx.play()
#player.velocity[0] = int(600 * dt * (ax - bx))
#player.velocity[1] = int(600 * dt * (ay - by))
#css1.velocity[0] = int(-600 * dt * bx)
#css1.velocity[1] = int(-600 * dt * by)
#css2.velocity = css1.velocity
#sat1.velocity = css1.velocity
#sat2.velocity = css1.velocity
#goal.velocity = css1.velocity
#wall1.velocity = css1.velocity
#wall2.velocity = css1.velocity
#wall3.velocity = css1.velocity
#wall4.velocity = css1.velocity
#ast1.velocity[0] = int(-200 * dt * bx)
#ast1.velocity[1] = int(-200 * dt * by)
#ast2.velocity[0] = int(-150 * dt * bx)
#ast2.velocity[1] = int(-150 * dt * by)
#ast3.velocity[0] = int(-120 * dt * bx)
#ast3.velocity[1] = int(-120 * dt * by)
player.update() player.update()
css1.update() css1.update()
css2.update() css2.update()
@ -352,6 +319,10 @@ while running:
screen.blit(sat1.image, sat1.rect) screen.blit(sat1.image, sat1.rect)
screen.blit(sat2.image, sat2.rect) screen.blit(sat2.image, sat2.rect)
screen.blit(goal.image, goal.rect) screen.blit(goal.image, goal.rect)
screen.blit(wall1.image, wall1.rect)
screen.blit(wall2.image, wall2.rect)
screen.blit(wall3.image, wall3.rect)
screen.blit(wall4.image, wall4.rect)
elif complete: elif complete:
playhr = (int(runtime / 3600000)) playhr = (int(runtime / 3600000))
playmin = (int(runtime / 60000) - (playhr * 60)) playmin = (int(runtime / 60000) - (playhr * 60))

BIN
sprites/wallh.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

BIN
sprites/wallh.png~ Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

BIN
sprites/wallv.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

BIN
sprites/wallv.png~ Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB