generated from dvorakmortonxd/pygame-template
might aswell add the last changes before I unfinished the jam
This commit is contained in:
parent
8aa6154710
commit
a0e8d6a6ba
4 changed files with 47 additions and 11 deletions
22
levels.py
22
levels.py
|
|
@ -2,6 +2,9 @@ from render import load_sprite # this makes it so our function for rendering spr
|
||||||
import pygame
|
import pygame
|
||||||
tickd = 0
|
tickd = 0
|
||||||
dialognum = 0
|
dialognum = 0
|
||||||
|
playerx,playery = 596, 245
|
||||||
|
oldpx, oldpy = 596, 245
|
||||||
|
playerXc, playerYc = 0,0
|
||||||
DIALOGTEXT = "UNDEFINED"
|
DIALOGTEXT = "UNDEFINED"
|
||||||
def level1(screen, sheet, screen_width, screen_height, lastclickpos, basicfont, mouse, click, big_text, level, tick, slightfont, pygamemixer): # the function for our first level, ignore the unused variables here, you can use them when you edit it
|
def level1(screen, sheet, screen_width, screen_height, lastclickpos, basicfont, mouse, click, big_text, level, tick, slightfont, pygamemixer): # the function for our first level, ignore the unused variables here, you can use them when you edit it
|
||||||
global tickd
|
global tickd
|
||||||
|
|
@ -13,7 +16,7 @@ def level1(screen, sheet, screen_width, screen_height, lastclickpos, basicfont,
|
||||||
screen.blit(overlay, (0, 0))
|
screen.blit(overlay, (0, 0))
|
||||||
elif tickd > 450:
|
elif tickd > 450:
|
||||||
tickd = 0
|
tickd = 0
|
||||||
mainmenu_text = slightfont.render("THE DESTROYER OF CITIES", True, (210, 210, 210))
|
mainmenu_text = slightfont.render("THE LARVAE", True, (210, 210, 210))
|
||||||
playb_collision = pygame.Rect(315, 200, 285, 105)
|
playb_collision = pygame.Rect(315, 200, 285, 105)
|
||||||
exitb_collision = pygame.Rect(315, 350, 285, 105)
|
exitb_collision = pygame.Rect(315, 350, 285, 105)
|
||||||
if playb_collision.collidepoint(mouse.get_pos()):
|
if playb_collision.collidepoint(mouse.get_pos()):
|
||||||
|
|
@ -38,10 +41,10 @@ def level1(screen, sheet, screen_width, screen_height, lastclickpos, basicfont,
|
||||||
screen.blit(load_sprite(sheet, 57, 0, 19, 7, 285, 105), (315, 350))
|
screen.blit(load_sprite(sheet, 57, 0, 19, 7, 285, 105), (315, 350))
|
||||||
exit_text = basicfont.render("Exit", True, (255,255,255))
|
exit_text = basicfont.render("Exit", True, (255,255,255))
|
||||||
screen.blit(exit_text, (414, 380))
|
screen.blit(exit_text, (414, 380))
|
||||||
screen.blit(mainmenu_text, (45, 65))
|
screen.blit(mainmenu_text, (255, 65))
|
||||||
return level # this returns the change we made to the level so that it updates in main.py
|
return level # this returns the change we made to the level so that it updates in main.py
|
||||||
def level2(blip, screen, sheet, screen_width, screen_height, lastclickpos, basicfont, mouse, click, big_text, level, tick, slightfont, pygamemixer): # the function for our first level, ignore the unused variables here, you can use them when you edit it
|
def level2(blip, screen, sheet, screen_width, screen_height, lastclickpos, basicfont, mouse, click, big_text, level, tick, slightfont, pygamemixer): # the function for our first level, ignore the unused variables here, you can use them when you edit it
|
||||||
global tickd, dialognum, DIALOGTEXT
|
global tickd, dialognum, DIALOGTEXT, playerx, playery
|
||||||
if dialognum not in [9, 11]:
|
if dialognum not in [9, 11]:
|
||||||
tickd += 1
|
tickd += 1
|
||||||
else:
|
else:
|
||||||
|
|
@ -106,7 +109,7 @@ def level2(blip, screen, sheet, screen_width, screen_height, lastclickpos, basic
|
||||||
if dialognum == 12:
|
if dialognum == 12:
|
||||||
DIALOGTEXT = "I'm the parasite..."
|
DIALOGTEXT = "I'm the parasite..."
|
||||||
screen.blit(load_sprite(sheet, 0, 37, 57,36, 912, 576), (0,0))
|
screen.blit(load_sprite(sheet, 0, 37, 57,36, 912, 576), (0,0))
|
||||||
screen.blit(load_sprite(sheet,57,40,6,28, 60, 280), (600, 290))
|
screen.blit(load_sprite(sheet,57,40,6,28, 60, 280), (playerx, playery))
|
||||||
dialog_square = pygame.surface.Surface((800, 68), pygame.SRCALPHA)
|
dialog_square = pygame.surface.Surface((800, 68), pygame.SRCALPHA)
|
||||||
dialog_square.fill((0, 0, 0))
|
dialog_square.fill((0, 0, 0))
|
||||||
screen.blit(dialog_square, (56, 500))
|
screen.blit(dialog_square, (56, 500))
|
||||||
|
|
@ -114,7 +117,7 @@ def level2(blip, screen, sheet, screen_width, screen_height, lastclickpos, basic
|
||||||
DIALOGTEXT = ""
|
DIALOGTEXT = ""
|
||||||
tickd = 0
|
tickd = 0
|
||||||
screen.blit(load_sprite(sheet, 0, 37, 57,36, 912, 576), (0,0))
|
screen.blit(load_sprite(sheet, 0, 37, 57,36, 912, 576), (0,0))
|
||||||
screen.blit(load_sprite(sheet,57,15,8,25, 80, 250), (660, 290))
|
screen.blit(load_sprite(sheet,57,40,6,28, 60, 280), (600, 290))
|
||||||
level = 3
|
level = 3
|
||||||
dialog = basicfont.render(DIALOGTEXT, True, transparency)
|
dialog = basicfont.render(DIALOGTEXT, True, transparency)
|
||||||
if len(DIALOGTEXT) < 16:
|
if len(DIALOGTEXT) < 16:
|
||||||
|
|
@ -136,10 +139,10 @@ def level2(blip, screen, sheet, screen_width, screen_height, lastclickpos, basic
|
||||||
return level # returns the current level set
|
return level # returns the current level set
|
||||||
|
|
||||||
def level3(blip, screen, sheet, screen_width, screen_height, lastclickpos, basicfont, mouse, click, big_text, level, tick, slightfont, pygamemixer): # the function for our first level, ignore the unused variables here, you can use them when you edit it
|
def level3(blip, screen, sheet, screen_width, screen_height, lastclickpos, basicfont, mouse, click, big_text, level, tick, slightfont, pygamemixer): # the function for our first level, ignore the unused variables here, you can use them when you edit it
|
||||||
global tickd
|
global tickd, playerx, playery
|
||||||
tickd += 1
|
tickd += 1
|
||||||
screen.blit(load_sprite(sheet, 0, 37, 57, 36, 912, 576), (0, 0))
|
screen.blit(load_sprite(sheet, 0, 37, 57, 36, 912, 576), (0, 0))
|
||||||
screen.blit(load_sprite(sheet,57,15,8,25, 80, 250), (660, 290))
|
screen.blit(load_sprite(sheet,57,40,6,28, 60, 280), (playerx, playery))
|
||||||
square = pygame.surface.Surface((812, 476), pygame.SRCALPHA)
|
square = pygame.surface.Surface((812, 476), pygame.SRCALPHA)
|
||||||
square.fill((0, 0, 0))
|
square.fill((0, 0, 0))
|
||||||
if tickd < 255:
|
if tickd < 255:
|
||||||
|
|
@ -162,8 +165,7 @@ def level3(blip, screen, sheet, screen_width, screen_height, lastclickpos, basic
|
||||||
return level
|
return level
|
||||||
|
|
||||||
def level4(blip, screen, sheet, screen_width, screen_height, lastclickpos, basicfont, mouse, click, big_text, level, tick, slightfont, pygamemixer): # the function for our first level, ignore the unused variables here, you can use them when you edit it
|
def level4(blip, screen, sheet, screen_width, screen_height, lastclickpos, basicfont, mouse, click, big_text, level, tick, slightfont, pygamemixer): # the function for our first level, ignore the unused variables here, you can use them when you edit it
|
||||||
global tickd
|
global tickd,playerx,playery, playerXc, playerYc
|
||||||
tickd += 1
|
|
||||||
screen.blit(load_sprite(sheet, 0, 37, 57, 36, 912, 576), (0, 0))
|
screen.blit(load_sprite(sheet, 0, 37, 57, 36, 912, 576), (0, 0))
|
||||||
screen.blit(load_sprite(sheet,57,15,8,25, 80, 250), (660, 290))
|
screen.blit(load_sprite(sheet,57,40,6,28, 60, 280), (playerx, playery))
|
||||||
return level
|
return level
|
||||||
36
main.py
36
main.py
|
|
@ -13,7 +13,7 @@ def main(fps=window_fps): # the main function
|
||||||
screen_width = 912 # the screen width
|
screen_width = 912 # the screen width
|
||||||
screen_height = 576 # the screen height
|
screen_height = 576 # the screen height
|
||||||
# THE SCREEN IS 19:12 RATIO
|
# THE SCREEN IS 19:12 RATIO
|
||||||
title = "The Destroyer of Cities" # the title of the window obviously
|
title = "The Larvae" # the title of the window obviously
|
||||||
lastclickpos = [0, 0] # last position that was clicked, this changes every time you click somewhere on the game window
|
lastclickpos = [0, 0] # last position that was clicked, this changes every time you click somewhere on the game window
|
||||||
screen = pygame.display.set_mode((screen_width, screen_height)) # this initializes the display with the screen_width and screen_height variables
|
screen = pygame.display.set_mode((screen_width, screen_height)) # this initializes the display with the screen_width and screen_height variables
|
||||||
pygame.display.set_caption(title) # this actually sets the title of the window from the title variable
|
pygame.display.set_caption(title) # this actually sets the title of the window from the title variable
|
||||||
|
|
@ -28,6 +28,7 @@ def main(fps=window_fps): # the main function
|
||||||
level = 1 # the level variable, this also gets changed during the "gameplay"
|
level = 1 # the level variable, this also gets changed during the "gameplay"
|
||||||
running = True # this variable starts the game loop
|
running = True # this variable starts the game loop
|
||||||
while running: # game loop
|
while running: # game loop
|
||||||
|
levels.oldpx, levels.oldpy = levels.playerx, levels.playery
|
||||||
screen.fill((0, 0, 0)) # fills the screen with black, so the sprites loaded previously dont overlap and this clears the last frame every "tick"
|
screen.fill((0, 0, 0)) # fills the screen with black, so the sprites loaded previously dont overlap and this clears the last frame every "tick"
|
||||||
for event in pygame.event.get(): # this checks for stuff like key presses and mouse clicks
|
for event in pygame.event.get(): # this checks for stuff like key presses and mouse clicks
|
||||||
if event.type == pygame.QUIT: # what happens when you click the X button on the window
|
if event.type == pygame.QUIT: # what happens when you click the X button on the window
|
||||||
|
|
@ -41,6 +42,17 @@ def main(fps=window_fps): # the main function
|
||||||
if level == 3:
|
if level == 3:
|
||||||
tickd = 0
|
tickd = 0
|
||||||
level = 4
|
level = 4
|
||||||
|
|
||||||
|
if level > 3:
|
||||||
|
if event.key == pygame.K_w:
|
||||||
|
levels.playerYc = -3
|
||||||
|
if event.key == pygame.K_a:
|
||||||
|
levels.playerXc = -3
|
||||||
|
if event.key == pygame.K_s:
|
||||||
|
levels.playerYc = +3
|
||||||
|
if event.key == pygame.K_d:
|
||||||
|
levels.playerXc = +3
|
||||||
|
|
||||||
if event.key == pygame.K_h:
|
if event.key == pygame.K_h:
|
||||||
if levels.dialognum == 9:
|
if levels.dialognum == 9:
|
||||||
levels.tickd = 0
|
levels.tickd = 0
|
||||||
|
|
@ -49,6 +61,16 @@ def main(fps=window_fps): # the main function
|
||||||
if levels.dialognum == 11:
|
if levels.dialognum == 11:
|
||||||
levels.tickd = 0
|
levels.tickd = 0
|
||||||
levels.dialognum = 12
|
levels.dialognum = 12
|
||||||
|
if event.type == pygame.KEYUP:
|
||||||
|
if level > 3:
|
||||||
|
if event.key == pygame.K_w:
|
||||||
|
playerYc = 0
|
||||||
|
if event.key == pygame.K_a:
|
||||||
|
playerXc = 0
|
||||||
|
if event.key == pygame.K_s:
|
||||||
|
playerYc = 0
|
||||||
|
if event.key == pygame.K_d:
|
||||||
|
playerXc = 0
|
||||||
if event.type == pygame.MOUSEBUTTONDOWN: # what happens when you press down a mouse button
|
if event.type == pygame.MOUSEBUTTONDOWN: # what happens when you press down a mouse button
|
||||||
click = True # sets the click variable to True so level function in levels.py can see
|
click = True # sets the click variable to True so level function in levels.py can see
|
||||||
print(pygame.mouse.get_pos()) # prints out where the mouse is during the click for debugging purposes
|
print(pygame.mouse.get_pos()) # prints out where the mouse is during the click for debugging purposes
|
||||||
|
|
@ -67,6 +89,18 @@ def main(fps=window_fps): # the main function
|
||||||
level = levels.level4(blip, screen, sheet, screen_width, screen_height, lastclickpos, basicfont, pygame.mouse, click, bigfont, level, tick, slightly_smaller_than_bigfont, pygame.mixer.music)
|
level = levels.level4(blip, screen, sheet, screen_width, screen_height, lastclickpos, basicfont, pygame.mouse, click, bigfont, level, tick, slightly_smaller_than_bigfont, pygame.mixer.music)
|
||||||
fps_text = sysfont.render(str(int(clock.get_fps())), True, (0, 255, 0)) # defines a thing that renders your fps in the top left corner
|
fps_text = sysfont.render(str(int(clock.get_fps())), True, (0, 255, 0)) # defines a thing that renders your fps in the top left corner
|
||||||
#screen.blit(fps_text, (5, 5)) # this actually renders "ftp_text" on the screen at the position (5, 5) which is the top left corner
|
#screen.blit(fps_text, (5, 5)) # this actually renders "ftp_text" on the screen at the position (5, 5) which is the top left corner
|
||||||
|
if 180 > levels.playerx:
|
||||||
|
levels.playerx = 180
|
||||||
|
if 615 < levels.playerx:
|
||||||
|
levels.playerx = 615
|
||||||
|
if 165 > levels.playery:
|
||||||
|
levels.playery = 165
|
||||||
|
if 275 < levels.playery:
|
||||||
|
levels.playery = 275
|
||||||
|
levels.playerx += levels.playerXc
|
||||||
|
levels.playery += levels.playerYc
|
||||||
|
|
||||||
|
|
||||||
pygame.display.flip() # this updates the display so it displays all the new stuff we added
|
pygame.display.flip() # this updates the display so it displays all the new stuff we added
|
||||||
clock.tick(fps) # this makes sure the game loop runs at the fps we set it to before
|
clock.tick(fps) # this makes sure the game loop runs at the fps we set it to before
|
||||||
pygame.quit() #this quits our game when the game loop somehow ends, for example by pressing escape or the X button on the window
|
pygame.quit() #this quits our game when the game loop somehow ends, for example by pressing escape or the X button on the window
|
||||||
|
|
|
||||||
BIN
sprites.png
BIN
sprites.png
Binary file not shown.
|
Before Width: | Height: | Size: 7.5 KiB After Width: | Height: | Size: 8.3 KiB |
BIN
sprites.pxo
BIN
sprites.pxo
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue