This repository has been archived by the owner on Sep 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·109 lines (82 loc) · 2.44 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
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import pygame
from pygame.locals import *
from game_objects import (Player, Enemy, Bullet)
from engine.color import Color
from engine.vec2 import Vec2
from engine.sprite import SpriteBase
import process
# import packages
sys.path.insert(0, 'path')
# inicia pygame
pygame.init()
BASE_DIR = os.path.dirname(os.path.abspath('__file__')) + '/'
display = pygame.display.Info()
# FULLSCREEN
FS = False
if len(pygame.display.list_modes(display.bitsize)) <= 2:
SCREEN_SIZE = pygame.display.list_modes(display.bitsize)[1]
else:
SCREEN_SIZE = (display.current_w, display.current_h)
def path(name, type_of_resource='sprite'):
"""Return absolute path to file
Keyword arguments:
name -- file name
type_of_resource - sprite, sound, ...
"""
if type_of_resource == 'sprite':
return BASE_DIR + 'assets/sprites/' + name
elif type_of_resource == 'sound':
return BASE_DIR + 'assets/sound/' + name
# Dicionario com todos os arquivos de midia do jogo
resource = {
'spacecraft': path('spacecraft.png', 'sprite'),
'enemy00': path('ship_enemy_00.png', 'sprite'),
'bg': path('bg_001.gif', 'sprite'),
'fire': path('fireb.png', 'sprite'),
'explosion': path('explosion.ogg', 'sound'),
'sound': path('hot.ogg', 'sound')
}
process.resource = resource
if FS:
screen = pygame.display.set_mode(SCREEN_SIZE, FULLSCREEN, display.bitsize)
else:
screen = pygame.display.set_mode((800, 600), 0, display.bitsize)
clock = pygame.time.Clock()
FPS = 60
background = pygame.image.load(resource['bg']).convert()
# Player
player = Player(200, 400, resource['spacecraft'])
# Enemy
for i, inimigos in enumerate(range(10)):
fn = Enemy(0, 10, resource['enemy00'])
def stereo_pan(x, width):
rv = float(x)/width
lv = 1.0 - rv
return(lv, rv)
last_key = None
while True:
# Eventos
key = pygame.key.get_pressed()
# Eventos
# < Logica
dt = clock.tick(FPS)/1000.0
"""Background color: cornflower (101, 156, 239)"""
screen.fill(Color.BLACK)
# screen.blit(background, Vec2.ZERO)
Enemy.update(dt)
Bullet.update(dt)
player.update(dt)
process.collision(player)
process.keyboard(player, dt, key, last_key)
# < Draw
# Renderiza todos os sprites
SpriteBase.group.draw(screen)
Bullet.List.draw(screen)
# Draw >
pygame.display.flip()
elapsed = clock.tick(FPS)
last_key = key