Skip to content

Commit 10bce3e

Browse files
committed
wip
1 parent 84bd251 commit 10bce3e

7 files changed

+75
-33
lines changed

__init__.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import os
22

33
PROJECT_DIR = os.path.dirname(os.path.realpath(__file__))
4+
SCREEN_WIDTH=960
5+
SCREEN_HEIGHT=320
6+
GAME_MODE="play"
47
COLORS = {
58
'BLACK': (0, 0, 0),
69
'WHITE': (255, 255, 255),
710
'BLUE': (50, 50, 255),
811
'RED': (175, 10, 10),
912
}
1013

11-
SCREEN_WIDTH=960
12-
SCREEN_HEIGHT=320
14+
OPTIONS = {
15+
'GAME_MODE': 'play'
16+
}

__main__.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import pygame
2-
2+
from sys import argv
33
from nax import SCREEN_WIDTH, SCREEN_HEIGHT
44
from nax.window import Window
5+
from nax.setting import setting
6+
7+
8+
if 2 <= len(argv):
9+
setting.game_mode = argv[1]
510

6-
SCREEN_WIDTH = 960
7-
SCREEN_HEIGHT = 320
811
win = Window(SCREEN_WIDTH, SCREEN_HEIGHT)
912
win.run()

game.py

+15-13
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
from nax.level_01 import Level01
44
from nax import PROJECT_DIR, COLORS
55
from nax.timer import GameTimer
6-
from time import time, sleep
7-
6+
from time import sleep
7+
from nax.setting import setting
88

99
class Game():
1010
def __init__(self, screen):
1111
self.screen = screen
1212
self.timer = GameTimer()
13-
self.player = Player(50, 50, 15)
13+
self.player = Player(0, 0, 15)
1414
self.level = Level01(self.player)
1515
self.platform_sprites = self.level.get_sprites()
1616
self.player.walls = self.platform_sprites
@@ -22,13 +22,6 @@ def __init__(self, screen):
2222
def event(self, event):
2323
if event.type == pygame.QUIT:
2424
return True
25-
26-
elif self.is_player_win():
27-
self.timer.stop()
28-
self.display_win_screen(self.screen)
29-
sleep(5)
30-
return True
31-
3225
elif event.type == pygame.KEYDOWN:
3326
if event.key == pygame.K_LEFT:
3427
self.player.go_left()
@@ -44,24 +37,33 @@ def event(self, event):
4437
self.player.stop()
4538
elif event.key == pygame.K_SPACE:
4639
self.player.jump(1)
47-
self.player.can_jump = False
40+
if not setting.is_dev_mode():
41+
self.player.can_jump = False
4842

4943
return False
5044

5145
def update(self):
46+
print(self.player.is_die)
47+
if self.player.is_die:
48+
self.display_die_screen()
49+
sleep(6)
50+
5251
for enemy in self.level.enemy_list:
5352
if enemy.is_die:
5453
self.level.enemy_list.remove(enemy)
5554

5655
self.all_sprite_list.update()
5756
self.level.update()
5857

59-
if self.player.is_die:
60-
self.display_die_screen()
58+
if self.player.has_win:
59+
self.display_win_screen(self.screen)
6160
sleep(6)
6261
pygame.event.post(pygame.event.Event(pygame.QUIT))
6362

6463

64+
# pygame.event.post(pygame.event.Event(pygame.QUIT))
65+
66+
6567
def draw(self):
6668
self.level.draw(self.screen)
6769
# self.screen.blit(self.player.hearts.image)

items.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@
44

55
class Platform(pygame.sprite.Sprite):
66
""" Wall the player can run into. """
7-
def __init__(self, x, y, width, height):
7+
def __init__(self, x, y, width, height, color='BLUE'):
88
""" Constructor for the wall that the player can run into. """
99
# Call the parent's constructor
1010
super().__init__()
1111

1212
# Make a blue wall, of the size specified in the parameters
1313
self.image = pygame.Surface([width, height])
14-
self.image.fill(COLORS.get('BLUE'))
14+
self.image.fill(COLORS.get(color))
1515

1616
# Make our top-left corner the passed-in location.
1717
self.rect = self.image.get_rect()
1818
self.rect.y = y
1919
self.rect.x = x
20+
self.is_end = False
2021

2122

2223
class Background(pygame.sprite.Sprite):

level_01.py

+19-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pygame
22
from nax import SCREEN_HEIGHT, PROJECT_DIR, COLORS
33
from nax.level import Level
4-
from nax.items import Background
4+
from nax.items import Background, Platform
55
from nax.enemy import Enemy
66

77

@@ -15,25 +15,40 @@ def __init__(self, player):
1515

1616
self.add_platforms([
1717
# x, y, with, screen_height
18-
[0, SCREEN_HEIGHT - 15, 200, 15],
18+
[0, SCREEN_HEIGHT - 15, 100, 15],
1919
[250, SCREEN_HEIGHT - 15, 550, 15],
2020
[350, SCREEN_HEIGHT - 85, 350, 15],
2121
[1000, SCREEN_HEIGHT - 15, 50, 15],
22-
[1200, SCREEN_HEIGHT - 15, 550, 15]
22+
[1200, SCREEN_HEIGHT - 15, 550, 15],
23+
[1400, SCREEN_HEIGHT - 85, 50, 15],
24+
[1550, SCREEN_HEIGHT - 125, 50, 15],
25+
[1870, SCREEN_HEIGHT - 100, 80, 15],
26+
[2050, SCREEN_HEIGHT - 15, 20, 15],
27+
[2150, SCREEN_HEIGHT - 15, 20, 15],
28+
[2250, SCREEN_HEIGHT - 45, 20, 45],
29+
[2250, 0, 20, 160],
2330
])
2431

32+
platform = Platform(2500, 0, 20, SCREEN_HEIGHT, 'WHITE')
33+
platform.is_end = True
34+
35+
self.platform_list.add(platform)
36+
2537
self.enemy_list = pygame.sprite.Group()
2638

2739
enemy = Enemy(300, 200)
2840
enemy.walls = self.platform_list
2941
enemy.player = player
30-
3142
self.enemy_list.add(enemy)
3243

3344
enemy = Enemy(480, 100)
3445
enemy.walls = self.platform_list
3546
enemy.player = player
47+
self.enemy_list.add(enemy)
3648

49+
enemy = Enemy(1430, 100, 3)
50+
enemy.walls = self.platform_list
51+
enemy.player = player
3752
self.enemy_list.add(enemy)
3853

3954
def draw(self, screen):

player.py

+17-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import pygame
22
from nax.items import Background
33
from nax.spritesheet import SpriteSheet
4-
from nax import PROJECT_DIR, SCREEN_HEIGHT, COLORS
4+
from nax import PROJECT_DIR, SCREEN_HEIGHT, COLORS, OPTIONS
5+
from nax.setting import setting
56

67

78
class Player(pygame.sprite.Sprite):
89
""" This class represents the bar at the bottom that the player
910
controls. """
1011

1112
# Constructor function
12-
def __init__(self, x, y, speed=10):
13+
def __init__(self, x=0, y=0, speed=10):
1314
# Call the parent's constructor
1415
super().__init__()
1516

@@ -88,6 +89,9 @@ def __init__(self, x, y, speed=10):
8889
# Custom
8990
self.speed = speed
9091
self.can_jump = True
92+
self.rect.x = x
93+
self.rect.y = y
94+
self.has_win = False
9195

9296
def stop(self):
9397
self.change_x = 0
@@ -139,6 +143,10 @@ def _calc_hit_walls(self):
139143
# See if we hit anything
140144
block_hit_list = pygame.sprite.spritecollide(self, self.walls, False)
141145
for block in block_hit_list:
146+
if block.is_end:
147+
self.has_win = True
148+
return
149+
142150
# If we are moving right,
143151
# set our right side to the left side of the item we hit
144152
if self.change_x > 0:
@@ -170,12 +178,12 @@ def _calc_grav(self):
170178
else:
171179
self.change_y += 1.35
172180

173-
# if self.change_y > SCREEN_HEIGHT:
174-
# pygame.event.post(pygame.QUIT)
175-
# See if we are on the ground.
176-
if self.rect.y >= SCREEN_HEIGHT - self.rect.height and self.change_y >= 0:
177-
self.change_y = 0
178-
self.rect.y = SCREEN_HEIGHT - self.rect.height
181+
if self.change_y > SCREEN_HEIGHT and not setting.is_dev_mode():
182+
self.is_die = True
183+
# pygame.event.post(pygame.QUIT)
184+
# elif self.rect.y >= SCREEN_HEIGHT - self.rect.height and self.change_y >= 0:
185+
# self.change_y = 0
186+
# self.rect.y = SCREEN_HEIGHT - self.rect.height
179187

180188
def _calc_collide_enemies(self):
181189
block_hit_list = pygame.sprite.spritecollide(self, self.enemy_list, False)
@@ -187,7 +195,7 @@ def _calc_collide_enemies(self):
187195
if self.lives >= 0:
188196
self.hearts.remove(self.hearts.sprites()[-1])
189197

190-
if self.lives == 0:
198+
if self.lives == 0 and not setting.is_dev_mode():
191199
self.is_die = True
192200

193201
# self.hearts.remove(self.hearts.)

setting.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Setting:
2+
def __init__(self):
3+
self.game_mode = "play"
4+
5+
def is_dev_mode(self):
6+
return self.game_mode == "dev"
7+
8+
9+
setting = Setting()

0 commit comments

Comments
 (0)