-
Notifications
You must be signed in to change notification settings - Fork 0
/
Scene.py
100 lines (77 loc) · 2.76 KB
/
Scene.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
import pygame
from pygame.locals import (
K_UP,
K_DOWN,
K_LEFT,
K_RIGHT,
)
import Player
WHITE = (255,255,255)
BLACK = (0,0,0)
RED = (255,0,0)
GREEN = (0,255,0)
BLUE = (0,0,255)
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
SCALED_SCREEN_WIDTH = 320
SCALED_SCREEN_HEIGHT = 240
SCREEN_CENTRE_X = SCREEN_WIDTH // 2
SCREEN_CENTRE_Y = SCREEN_HEIGHT // 2
PLAYER_CENTER_X = SCALED_SCREEN_WIDTH // 2
PLAYER_CENTRE_Y = SCALED_SCREEN_HEIGHT // 2
player = Player.Player()
player.x_pos = PLAYER_CENTER_X
player.y_pos = PLAYER_CENTRE_Y
speed = player.speed
class Scene():
def __init__(self):
self.next_scene = None
def terminate_scene(self):
self.next_scene = None
class PlayScene(Scene):
def __init__(self, map=None):
super().__init__()
self.world = map
self.width = self.world.get_width()
self.height = self.world.get_height()
self.world_x = SCREEN_WIDTH - self.width
self.world_y = SCREEN_HEIGHT - self.height
def controls(self, pressed_keys):
if pressed_keys[K_DOWN] and player.y_pos >= PLAYER_CENTRE_Y:
self.world_y -= speed
elif pressed_keys[K_DOWN] and player.y_pos < PLAYER_CENTRE_Y:
player.y_pos += speed
if pressed_keys[K_UP] and player.y_pos <= PLAYER_CENTRE_Y:
self.world_y += speed
elif pressed_keys[K_UP] and player.y_pos > PLAYER_CENTRE_Y:
player.y_pos -= speed
if pressed_keys[K_RIGHT] and player.x_pos >= PLAYER_CENTER_X:
self.world_x -= speed
elif pressed_keys[K_RIGHT] and player.x_pos < PLAYER_CENTER_X:
player.x_pos += speed
if pressed_keys[K_LEFT] and player.x_pos <= PLAYER_CENTER_X:
self.world_x += speed
elif pressed_keys[K_LEFT] and player.x_pos > PLAYER_CENTER_X:
player.x_pos -= speed
if self.world_x < -self.width + SCALED_SCREEN_WIDTH:
self.world_x = -self.width + SCALED_SCREEN_WIDTH
player.x_pos += speed
if self.world_x > 0:
self.world_x = 0
player.x_pos -= speed
if self.world_y < -self.height + SCALED_SCREEN_HEIGHT:
self.world_y = -self.height + SCALED_SCREEN_HEIGHT
player.y_pos += speed
if self.world_y > 0:
self.world_y = 0
player.y_pos -= speed
def process_events(self, events):
pass
def update(self):
pass
def render(self):
scaled_screen = pygame.Surface((SCALED_SCREEN_WIDTH, SCALED_SCREEN_HEIGHT))
scaled_screen.blit(self.world, [self.world_x, self.world_y])
scaled_screen.blit(player.surf, [player.x_pos, player.y_pos])
screen = pygame.display.get_surface()
pygame.transform.scale(scaled_screen, (800, 600), screen)