我确实设置了一种奇怪的装备,我有一个运行 RetroPie 的 Raspberry Pi,我更改了控制台配置以添加一个系统 python,它只是从名为 python 的 ROM 文件夹中的文件运行 python 脚本,命令行简单执行所需的 python 脚本。
好吧,这在我的 Pygame 脚本中运行良好,直到我将它放入全屏。游戏明显变慢了,所以我把它改回原来的代码,窗口只有屏幕大小的一半。
为了尝试解决这个问题,我使用了以下代码:
display_width, display_height = 600, 600
print(str(display_width) + " " + str(display_height))
gameDisplay = pygame.display.set_mode((display_width, display_height))
print(pygame.display.get_window_size())
#header title
pygame.display.set_caption("Pirate Pigs!!!")
print(pygame.display.get_window_size())
而且无论我在 set_mode 中放什么,它总是以全屏 1280,720 打开窗口。我认为这可能是 RetroPie 或 RetroArch 的问题,但它并没有用来执行此操作,并且自问题发生以来我没有更改任何 RetroPie 配置
我还尝试制作另一个仅打开 400、400 窗口的脚本,但仍将其打开至 1280、720
我还认为这可能是一个错误,因为我的图像 ship.bmp 比窗口大,即使我删除它,错误仍然存在
谢谢,吨的所有帮助!
如果有帮助,这是我的完整代码:
#Noah Hall
#03/29/2021
#PiratePigs
#to orun you need these files:
#highscore.txt
#an assets file containing the following:
#Bullet.bmp
#EvilPiratePig.bmp
#FlyingPiratePig.bmp
#PiratePigChar0.bmp
#SharpShooterPiratePig.bmp
#Ship.png
#Run this main.py file in the same file as the assets file and the highscore.txt and have the pygame library installed
#If py game is not installed type this into your terminal: python3 -m pip install -U pygame --user for mac and py -m pip install -U pygame --user for windows
#is using windows, you must change all of the "/" - forward slashes to backslashes.
#you can thank old windows developers for making their command lines / for that
#Must be run on python 3 or greater and pygame 2.0 or greater
#Imports for pirate pigs
#library for game machanics
import pygame
#librarry for randomness
import random
#library for math operations for shooting angles
import math
import os
full_path = os.path.realpath(__file__)
os.chdir(os.path.dirname(full_path))
pygame.init()
#display initiation
#demintions of window
display_width, display_height = 600, 600
print(str(display_width) + " " + str(display_height))
gameDisplay = pygame.display.set_mode((display_width, display_height))
print(pygame.display.get_window_size())
#header title
pygame.display.set_caption("Pirate Pigs!!!")
print(pygame.display.get_window_size())
#variable colors
black = (0, 0, 0)
white = (255, 255, 255)
bg = (115, 190, 255)
#start time
clock = pygame.time.Clock()
#Is game loop var
crashed = False
#object positions relitive to this overall position which defines the camera
gameX = 0
gameY = 0
#maxshots in a row, used to prevent lag
ammo = 15
#ticker instuctions pages
sclock = 1
#is the shop showing
shop = False
#progress vars
wave = 0
score = 0
#your bullet speed
bspeed = 15
#shielding
shield = False
#Shut down game after loss
Lose = False
#give the last direction moved
lastDir = "LEFT"
select = 0
costmult = 1
#classes
class Char:
def __init__(self, img, x, y, speed, hitx, hity, health):
#all Vars to basic character
self.img = pygame.image.load(img)
self.x = x
self.y = y
self.speed = speed
self.hitx = hitx
self.hity = hity
self.IsJump = False
self.gravity = True
#velocity mass and force for gravity and jumping
self.v = 7
self.m = 1
self.F = 0
#health and strength
self.health = health
self.fullhealth = health
self.damage = 1
def draw(self):
#to be called when ready to blit on screen
#enable the gravity
if self.gravity == True:
#stops glitch that makes it where you sometimes fall through the floor
if onFloor(self.x, self.y) == "UNDER":
self.y = floorHeight(self.x, self.y)
print("Under floor")
if onFloor(self.x, self.y) == False and self.IsJump == False:
self.y += 5
if self.IsJump:
self.F = (1 / 2) * self.m * (self.v**2)
self.y -= self.F
self.v = self.v - 1
#reached vertex
if self.v < 0:
#goes back down
self.m = -1
#back to start
if self.v == -8:
# making isjump equal to false
self.IsJump = False
#reset velocity and mass
self.v = 7
self.m = 1
#blit to the canvas
pygame.draw.rect(gameDisplay,(255,0,0), (self.x, self.y + self.hity + 10, self.hitx, 5))
pygame.draw.rect(gameDisplay,(0,255,0), (self.x, self.y + self.hity + 10, self.hitx * (self.health/self.fullhealth), 5))
gameDisplay.blit(self.img, (self.x, self.y))
def move(self, dir):
#calls when you need the self to move
self.dir = dir
if self.dir == "LEFT":
self.x = self.x - self.speed
elif self.dir == "RIGHT":
self.x = self.x + self.speed
elif self.dir == "UP":
self.IsJump = True
else:
#tells me is i made a typo, I was tired on making this mistake
print("invalid Char.move direction")
def gravity(self, b):
#lowkey pretty pointless, but i used this for testing, and it is now stuck
self.gravity = b
def goto(self, x, y):
#teleport self, to be called by teleports
self.x = x
self.y = y
class Ememy(Char):
#class that inherits char, to use as the enemies
def __init__(self, img, x, y, speed, hitx, hity, kind, health):
Char.__init__(self, img, x, y, speed, hitx, hity, health)
#extra init to establish life and death and AI
self.kind = kind
self.alive = True
self.whichWay = 0
#create list for bullets to be updated and stored
self.bullets = []
#load image based on ememy type
if self.kind == 0:
self.img = pygame.image.load("assets/EvilPiratePig.bmp")
if self.kind == 2:
self.img = pygame.image.load("assets/SharpShooterPiratePig.bmp")
if self.kind == 1:
self.img = pygame.image.load("assets/FlyingPiratePig.bmp")
def draw(self):
#walking bad pig
if self.kind == 0:
#code for following player
if player.x + gameX > 790 and player.x + gameX < 2990:
if player.x > self.x - gameX:
self.x += self.speed
if player.x < self.x - gameX:
self.x -= self.speed
if self.x - gameX > player.x - 1 and self.x - gameX < player.x + player.hitx + 1 and self.y - gameY > player.y - 1 and self.y - gameY < player.y + player.hity + 5:
player.health -= 1
self.alive = False
if self.health <= 0:
self.alive = False
#flying bad pig
if self.kind == 1:
#code for flying pig
if self.y > 300:
self.whichWay = 0
if self.y < 100:
self.whichWay = 1
if self.whichWay == 0:
self.y -= self.speed
if self.whichWay == 1:
self.y += self.speed
#shoot bullets on average every one and a half seconds in both directions
if random.randint(0, 60*1.5) == 1:
self.bullets.append(Projectile("assets/Bullet.bmp", self.x, self.y, 0, 3))
self.bullets.append(Projectile("assets/Bullet.bmp", self.x, self.y, 180, 3))
for obj in self.bullets:
obj.shoot()
obj.draw()
#shooting
if self.kind == 2:
#code for randomly shooting in random direction on average every half second
if random.randint(0, 30) == 1:
self.bullets.append(Projectile("assets/Bullet.bmp", self.x, self.y, random.randint(-180,180), 3))
for obj in self.bullets:
obj.shoot()
obj.draw()
#Draw when in camera
if self.x - gameX > 0 and self.x - gameX < display_width and self.y - gameY > 0 and self.y - gameY < display_height:
pygame.draw.rect(gameDisplay,(255,0,0), (self.x - gameX, self.y - gameY + self.hity + 10, self.hitx, 5))
pygame.draw.rect(gameDisplay,(0,255,0), (self.x - gameX, self.y - gameY + self.hity + 10, self.hitx * (self.health/self.fullhealth), 5))
gameDisplay.blit(self.img, (self.x - gameX, self.y - gameY))
class Object:
#class for ordinary non moving objects
def __init__(self, img, x, y):
self.img = pygame.image.load(img)
self.x = x
self.y = y
def draw(self):
#blit this boring object
gameDisplay.blit(self.img, (self.x - gameX, self.y - gameY))
class Floor:
#defines horizontal hit box
def __init__(self, x, y, width, height):
self.x = x
self.y = y
self.width = width
self.height = height
class Wall:
#defines vertical hit boxes
def __init__(self, x, y, width, height, direction):
self.x = x
self.y = y
self.width = width
self.height = height
self.direction = direction
def onWallLeft():
#keeps player from walking through a defined wall on the left
for obj in wall:
if obj.x - gameX < player.x and obj.x + obj.width - gameX > player.x and obj.y - gameY < player.y and obj.y - gameY + obj.height > player.y and obj.direction == 1:
print("hitL")
player.x += 10
def onWallRight():
#keeps player from walking through a defined wall on the right
for obj in wall:
if obj.x - gameX < player.x and obj.x + obj.width - gameX > player.x and obj.y - gameY < player.y and obj.y - gameY + obj.height > player.y and obj.direction == -1:
print("hitR")
player.x -= 10
class TxtBox:
#makes making text boxes easy
def __init__(self, x, y, size):
#inital properties
self.x = x
self.y = y
self.size = size
#Set up font
self.font = pygame.font.SysFont('timesnewroman', size)
self.text = str("")
self.rend = 1
def draw(self):
#draw the text, blits it
self.rend = self.font.render(self.text, True, white)
#made a way to center text, becasue it was getting repetitive
if self.x == "CENTER":
self.textRect = self.rend.get_rect()
self.textRect.center = (display_width//2, self.y)
gameDisplay.blit(self.rend, (self.textRect))
else:
gameDisplay.blit(self.rend, (self.x, self.y))
self.text = ""
def setText(self, string):
#method for cahnging text
self.text = string
class Projectile(Object):
#class to create bullets
def __init__(self, img, x, y, dir, speed):
self.dir = dir
self.speed = speed
Object.__init__(self, img, x, y)
def shoot(self):
#code to update bullet position
self.x -= math.sin(math.radians(self.dir + 90)) * self.speed
self.y += math.cos(math.radians(self.dir + 90)) * self.speed
class Wave:
#class to create a wave of ememies
def __init__(self, difficulty, walking, flying, shooting):
#reset old wave, and make variables for amounts of new ememies
badPigs.clear()
self.difficulty = difficulty
self.walking = walking
self.flying = flying
self.shooting = shooting
self.count = self.walking + self.flying + self.shooting
def start(self):
#method for starting wave
for i in range(self.flying):
badPigs.append(Ememy("assets/PiratePigChar0.bmp", random.randint(300, 4000), 120, 5, 32, 32, 1, 3))
for i in range(self.walking):
badPigs.append(Ememy("assets/PiratePigChar0.bmp", random.randint(800, 3000), 295, 0.5, 32, 32, 0, 1))
for i in range(self.shooting):
badPigs.append(Ememy("assets/PiratePigChar0.bmp", random.randint(800, 3000), 295, 5, 32, 32, 2, 2))
def onFloor(x, y):
#medthod for testing is player is on the ground or in the air
for obj in floor:
if y + gameY > obj.y - 1 and y + gameY < obj.y + 1 and x + gameX > obj.x and x + gameX < obj.x + obj.width:
return True
elif y + gameY < obj.y + obj.height and y + gameY > obj.y - 1 and x + gameX > obj.x and x + gameX < obj.x + obj.width:
return str("UNDER")
else:
continue
return False
def floorHeight(x, y):
#this method returns the y position of the floor relitive to the camera
for obj in floor:
if y > obj.y - gameY - 1 and x > obj.x - gameX and x < obj.x - gameX + obj.width:
return obj.y - gameY
def highscore(score):
#this method updates the highscore if the score is higher than the previous highscore then it updates, this function always returns the current highscore
#opens the file to save the highscore
f = open('highscore.txt','r')
#assigns the var the data of the file
Highscore = f.read()
f.close()
if score > int(Highscore):
#if there is a new highscore write it to the file
Highscore = score
f = open('highscore.txt','a')
f.truncate(0)
f.write(str(Highscore))
f.close()
return Highscore
def highwave(Wave):
#this method updates the highscore if the score is higher than the previous highscore then it updates, this function always returns the current highscore
#opens the file to save the highscore
f = open('highWave.txt','r')
#assigns the var the data of the file
HighWave = f.read()
f.close()
if score > int(HighWave):
#if there is a new highscore write it to the file
HighWave = Wave
f = open('highWave.txt','a')
f.truncate(0)
f.write(str(HighWave))
f.close()
return HighWave
class Button:
#class for making buttons
def __init__(self, color, x,y,width,height):
self.x = x
self.y = y
self.width = width
self.height = height
self.color = color
def draw(self):
#draws the button
pygame.draw.rect(gameDisplay,self.color, (self.x, self.y, self.width, self.height))
##Method for computer mouse aim
## def isHover(self):
## #method for detecting hover on button
## if pos[0] > self.x and pos[0] < self.x + self.width and pos[1] > self.y and pos[1] < self.y + self.height:
## return True
## else:
## return False
def joyDir():
horiz_axis_pos = joystick[0].get_axis(1)
vert_axis_pos = joystick[0].get_axis(0)
if horiz_axis_pos > 0:
return str("RIGHT")
elif horiz_axis_pos < 0:
return str("LEFT")
elif vert_axis_pos > 0:
return str("DOWN")
elif vert_axis_pos < 0:
return str("UP")
else:
return False
def joyBut():
for j in range(joystick_count):
for i in range( joystick[j].get_numbuttons() ):
if joystick[j].get_button( i ) == True:
testTxt.setText("joystick" + str(j) + " " + str(i))
#init object's lists:
floor = []
wall = []
bullet = []
badPigs = []
waves = []
joystick = []
#init ship
myship = Object("assets/Ship.bmp", 0, -200)
#ship floors init
floor.append(Floor(0, 120, 760, 10))
floor.append(Floor(740, 295, 3315 - 740, 10))
floor.append(Floor(3315, 120, 760, 10))
wall.append(Wall(745, 120, 20, 200, 1))
wall.append(Wall(3300, 120, 30, 200, -1))
#intitalize player
player = Char("assets/PiratePigChar0.bmp", display_width / 2, 0, 5, 32, 32, 10)
#init test badguy
badPigs.append(Ememy("assets/PiratePigChar0.bmp", 300, 120, 5, 32, 32, 1, 2))
#init instruction
inst = TxtBox("CENTER", 75, 15)
inst2 = TxtBox("CENTER", 92, 15)
testTxt = TxtBox("CENTER", 100, 30)
#init score
scr = TxtBox(10,30, 15)
highscr = TxtBox(10,40, 15)
highwa = TxtBox(10,52, 15)
#Wave info
wavetxt = TxtBox("CENTER", 350, 20)
badpigleft = TxtBox("CENTER", 371, 10)
#waves
wave1 = Wave(0, 1, 0, 0)
wave2 = Wave(0, 3, 0, 1)
wave3 = Wave(0, 3, 1, 3)
wave4 = Wave(0, 3, 3, 3)
wave5 = Wave(0, 5, 10, 3)
#shop init
wel = TxtBox("CENTER", 75, 25)
xbox = TxtBox(display_width - 25, 0, 25)
shopinst = TxtBox("CENTER", 300, 20)
healthbutton = Button(white, display_width / 4 - 142, 95, 95, 95)
maxhealthbutton = Button(white, display_width / 2 - 142, 95, 95, 95)
gunspeedbutton = Button(white,(display_width * 3) / 4 - 142, 95, 95, 95)
gundamagebutton = Button(white, display_width - 142, 95, 95, 95)
#gun cooldown
cooldown = 10
cd = 10
#highscore read, init
f = open('highscore.txt','r')
Highscore = f.read()
print(Highscore)
f.close()
#highWave read, init
f = open('highWave.txt','r')
HighWave = f.read()
print(HighWave)
f.close()
click = False
#joystick init
joystick_count = pygame.joystick.get_count()
if joystick_count == 0:
# No joysticks!
print("Error, I didn't find any joysticks.")
else:
# Use joystick and initialize it
for i in range(joystick_count):
joystick.append(pygame.joystick.Joystick(i))
joystick[i].init()
keys = pygame.key.get_pressed()
#Loops for pirate pigs
while not crashed:
#initallizes keys and stores them in keys
#test for pygame events
for event in pygame.event.get():
keys = pygame.key.get_pressed()
#test for game quit
if event.type == pygame.QUIT:
crashed = True
#test for mouse button down
if joystick[0].get_button(7) == True:
click = True
else:
click = False
if keys[pygame.K_q] or joystick[0].get_button(11) == True:
crashed = True
#test for spacebar down
if event.type == pygame.KEYDOWN and keys[pygame.K_SPACE] or joystick[0].get_button(10) == True:
sclock += 1
#test for down arrow for shielding
if keys[pygame.K_s] or keys[pygame.K_DOWN] or joyDir() == "DOWN":
shield = True
else:
shield = False
#update vars
joyBut()
highscore(score)
highwave(wave)
#set text for dislay that constantly updates
scr.setText("Score: " + str(score))
highscr.setText("Highscore: " + str(Highscore))
highwa.setText("Highest Wave: " + str(highwave(wave)))
gameDisplay.fill(bg)
wavetxt.setText("You're on Wave: " + str(wave))
badpigleft.setText("There are " + str(len(badPigs)) + " pigs left")
#Game logic goes under here
#Keys Pressed
#Char Movement
if (keys[pygame.K_a] or keys[pygame.K_LEFT] or joyDir() == "LEFT") and player.x > 299 and shield == False:
player.move("LEFT")
lastDir = "LEFT"
if (keys[pygame.K_d] or keys[pygame.K_RIGHT] or joyDir() == "RIGHT") and player.x < display_width - 299 and shield == False:
# increment in x
player.move("RIGHT")
lastDir = "RIGHT"
if (keys[pygame.K_w] or keys[pygame.K_UP] or joystick[0].get_button(9) == True) and shield == False:
# increment in y force]
player.move("UP")
#Shooting
cd -= 1
#makes sure we are capable of shooting
if click and cd < 0 and shield == False:
#angle = math.degrees(math.atan2(player.y-0, player.x - 0))
if lastDir == "RIGHT":
angle = 180
if lastDir == "LEFT":
angle = 0
#make and shoot a bullet
bullet.append(Projectile("assets/Bullet.bmp", player.x + gameX, player.y + 15 + gameY, angle, bspeed))
print(len(bullet))
cd = cooldown
#loops through a copied list to test if bullet should show, used to reduce lag
for obj in bullet[:]:
if obj.x > display_width or obj.x < 0 or obj.y > display_height or obj.y < 0:
pass
if cd < -100 or len(bullet) > ammo + 1:
bullet.clear()
#loops through copied list to test is pig is hit
for i in badPigs[:]:
if obj.x > i.x and obj.x < i.x + i.hitx and obj.y > i.y and obj.y < i.y + i.hity:
i.health -= player.damage
#this code is used to fix a list error that would occur when a bullet hit two ememies at once and the list would try to delete the same ememy
try:
bullet.remove(obj)
except ValueError:
pass
obj.shoot()
#Loops through all ememy bullets to test if player was hit, and was not sheilding
for obj in badPigs[:]:
for i in obj.bullets[:]:
if i.x - gameX > player.x and i.x - gameX < player.x + player.hitx and i.y - gameY > player.y and i.y - gameY < player.y + player.hity and shield == False:
player.health -= 1
#fixes error where bullets from the list would try to get removed did not exist
try:
obj.bullets.remove(i)
except ValueError:
pass
i.shoot()
for i in badPigs[:]:
if i.alive == False or i.health == 0 or i.health < 0:
#fixes error where pig that did not exist tried to get removed
try:
badPigs.remove(i)
score += 10
except ValueError:
pass
#Moves camera position
if player.x < 300 and (keys[pygame.K_a] or keys[pygame.K_LEFT] or joyDir() == "LEFT"):
gameX = gameX - 5
if player.x > display_width - 300 and (keys[pygame.K_d] or keys[pygame.K_RIGHT] or joyDir() == "RIGHT"):
gameX = gameX + 5
if player.y > display_height - 200:
gameY = gameY + 5
player.y = player.y - 5
#call methods for kepping player in walls
onWallLeft()
onWallRight()
#Ship teleports
if player.x + gameX > 830 and player.x + gameX < 900:
inst2.setText("Press Space To Go Up")
if keys[pygame.K_SPACE] or joystick[0].get_button(10) == True:
player.goto(player.x - 250, 0)
gameY -= 100
print("executed left up")
#instruction and executing to enter the shop
if player.x + gameX > 700 and player.x + gameX < 780:
inst2.setText("Press Space To Enter Shop")
if keys[pygame.K_SPACE] or joystick[0].get_button(10) == True:
print("Enter Shop")
shop = True
else:
shop = False
if player.x + gameX > 3315 - 30 and player.x + gameX < 3315:
inst2.setText("Press Space To Go Up")
if keys[pygame.K_SPACE] or joystick[0].get_button(10) == True:
player.goto(player.x + 50, 0)
gameY -= 100
print("executed left up")
#pirate pigs gameplay
#instructions
if sclock == 1:
inst2.setText("Use the arrow keys to move (Press space to see next instructions)")
elif sclock == 2:
inst2.setText("Click to shoot at ememies")
elif sclock == 3:
inst2.setText("Kill all of the ememies in a wave to move on")
elif sclock == 4:
inst2.setText("The waves get harder as you go")
elif sclock == 5:
inst2.setText("Upgrade yourself in the shop to help you get far")
elif sclock == 6:
inst2.setText("If you lose all you heath you die")
else:
pass
#Once game begins show instructions for inital waves to get players comfortable with the game
if wave == 1:
inst2.setText("Dont let these guys run into you")
if wave == 2:
inst2.setText("There are so many!!!")
if wave == 3:
inst2.setText("These guys shoot all around")
if wave == 3:
inst2.setText("We got this in the bag until pigs fly... uh oh")
if len(badPigs) == 0:
inst.setText("Press return to move to next wave")
if(keys[pygame.K_RETURN] or joystick[0].get_button(4) == True):
wave += 1
#wave creation
#set parameters for the intals waves to follow with the instruction text
if wave == 1:
currentWave = Wave(0, 1, 0, 0)
inst2.setText("Dont let these guys run into you")
elif wave == 2:
currentWave = Wave(0, 3, 0, 0)
inst2.setText("There are so many!!!")
elif wave == 3:
currentWave = Wave(0, 0, 1, 0)
inst2.setText("These guys shoot all around")
elif wave == 4:
currentWave = Wave(0, 0, 0, 1)
inst2.setText("We got this in the bag until pigs fly... uh oh")
#seets rules for all waves after 4 and makes them, harder as you progress through the game
elif wave > 4 and wave < 15.1:
currentWave = Wave(1, round(wave),round(wave-3), round(wave-4))
elif wave > 15 and wave < 30.1:
currentWave = Wave(1, round(wave * 2),round(wave), round(wave))
elif wave > 30 and wave < 50.1:
currentWave = Wave(1, round(wave * 2.2),round(wave * 1.5), round(wave*1.5))
elif wave > 50 and wave < 100.1:
currentWave = Wave(1, round(wave * 2),round(wave * 2), round(wave*2))
elif wave > 100:
currentWave = Wave(round(4*(wave/100)), round(wave**1.05 * 3.5),round(wave**1.05 * 3), round(wave**1.05*2))
else:
currentWave.start()
currentWave.start()
#all drawing here
#use all the draw methods i nthe classes to blit and update odjects and characters and ememies
myship.draw()
player.draw()
inst.draw()
inst2.draw()
scr.draw()
testTxt.draw()
highscr.draw()
highwa.draw()
wavetxt.draw()
badpigleft.draw()
if len(badPigs) != 0:
pygame.draw.rect(gameDisplay,(255,0,0), (display_width/2 - 100, 375, 200, 5))
pygame.draw.rect(gameDisplay,(0,255,0), (display_width/2 - 100, 375, 200 * (len(badPigs)/currentWave.count), 5))
#draw from lists
for obj in bullet:
obj.draw()
for obj in badPigs:
obj.draw()
#########shop#########
#only allow entrence in the shop is you have positive money, or the shop will think you can bad credit
if shop and score > 0:
gameDisplay.fill((40,40,40))
if joyDir() == "LEFT":
select -= 1
if joyDir() == "RIGHT":
select += 1
if select > 3:
select = 0
if select < 0:
select = 3
#heath restore upgrade
if select == 0:
healthbutton.color = (200,200,200)
shopinst.setText("Restore health to the max, Cost: " + str(30))
else:
healthbutton.color = white
if select == 0 and click:
player.health = player.fullhealth
score -= 30
shop = False
#maxheath upgrade
if select == 1:
maxhealthbutton.color = (200,200,200)
shopinst.setText("Increase the max health level. Cost: " + str(5 * costmult))
else:
maxhealthbutton.color = white
if select == 1 and click:
player.fullhealth += 1
costmult += 1
score -= 5 * costmult
shop = False
#gun speed upgrade
if select == 2:
gunspeedbutton.color = (200,200,200)
shopinst.setText("Increase the speed of bullets. Cost:"+ str(10 * costmult))
else:
gunspeedbutton.color = white
if select == 2 and click:
bspeed += 1
costmult += 1
score -= 10 * costmult
shop = False
#gun damage upgrade
if select == 3:
gundamagebutton.color = (200,200,200)
shopinst.setText("Upgrade the amount of damage per bullet. Cost: " + str(10 * costmult))
else:
gundamagebutton.color = white
if select == 3 and click:
player.damage += 1
costmult += 1
shop = False
#Shop Drawings
#set the text for the shop
wel.setText("WELCOME TO THE SHOP")
xbox.setText("X")
#draw all of the buttons to the canvas
healthbutton.draw()
maxhealthbutton.draw()
gunspeedbutton.draw()
gundamagebutton.draw()
shopinst.draw()
#draw the text to the canvas
xbox.draw()
wel.draw()
elif shop and score < 0.1:
shopinst.setText("You need more money to enter shop")
shopinst.draw()
shopinst.setText("")
if player.health == 0 or player.health < 0:
Lose = True
if Lose == True:
gameDisplay.fill((40,40,40))
wel.setText("You are a loser")
wel.draw()
pygame.time.wait(60*30)
crashed = True
#testing script that shows me the x and y coords and their relative coords to the camera and the max health in the terminal
#update the display at 60 frames for second
pygame.display.update()
clock.tick(60)
#if out of the game loop quit the game
pygame.quit()
quit()