-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
98 lines (74 loc) · 2.58 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#importing files
import pygame
pygame.init()
#os to access files
import os
from mainMenu import *
from win import *
#Importing init functions from file
#Function wrap game's inits
#def gameInit():
# winFontInit()
# winMixerInit()
#gameInit()
winMixerInit()
#First window to appear when game starts
#mainMenu()
#BG image
GAME_BG_IMAGE = pygame.image.load(os.path.join('Assets', 'game1.png'))
GAME_BG_IMAGE_SCALE = pygame.transform.scale(GAME_BG_IMAGE, (800, 600))
PLAYER_IMAGE = pygame.image.load(os.path.join('Assets', 'player.png'))
PLAYER_IMAGE_SCALE = pygame.transform.scale(PLAYER_IMAGE, (160, 160))
VEL = 3
ENEMY_IMAGE = pygame.image.load(os.path.join('Assets', 'enemy.png'))
ENEMY_IMAGE_SCALE = pygame.transform.scale(ENEMY_IMAGE, (120, 120))
def main():
mainMenuScreen()
mainEvents()
#if event.type == pygame.MOUSEBUTTONDOWN:
#if event.button:
#mouseClicked = True
#print("Hola")
#if PLAY_BUTTON.collidepoint((mouse_x, mouse_y)):
#if mouseClicked:
#game()
#mouseClicked = False
#Podría ir en win.py
def mainEvents():
while 1:
mainClock.tick(SCREEN_FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
#gameRunning = False
pygame.quit()
break
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
pygame.quit()
def char_handle_movement(keypressed, character):
if keypressed[pygame.K_a]:
character.x -= VEL
if keypressed[pygame.K_d]:
character.x += VEL
def game():
character = pygame.Rect(30, 450, 160, 160)
mainDoor = pygame.Rect(400, 800, 130, 120)
gameRunning = True
while gameRunning:
mainClock.tick(SCREEN_FPS)
SCREEN.blit(PLAYER_IMAGE_SCALE, (character.x, character.y))
SCREEN.blit(ENEMY_IMAGE_SCALE, (530, 490))
SCREEN.blit(ENEMY_IMAGE_SCALE, (210, 490))
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
running = False
keypressed = pygame.key.get_pressed()
char_handle_movement(keypressed, character)
pygame.display.update()
if __name__ == "__main__":
#__name__ of the file and __main__ is the main file that was run
#This means main() will be excecuted when running this file
main()