1
1
import os
2
+ import pygame
2
3
from core .point import *
3
4
from tilemap import *
4
5
from spriteCollection import *
@@ -12,7 +13,16 @@ def __init__(self, game, imageCache, screenDimension):
12
13
self .screenDimension = screenDimension
13
14
14
15
self .cameraMouseOffset = Point (0 , 0 )
15
- self .rightMouseButtonDown = False
16
+ self .cameraDragging = False
17
+ self .arrowKeyState = {pygame .constants .K_UP : False , \
18
+ pygame .constants .K_DOWN : False , \
19
+ pygame .constants .K_LEFT : False , \
20
+ pygame .constants .K_RIGHT : False }
21
+ self .arrowKeyMovement = {pygame .constants .K_UP : Point (0 , 1 ), \
22
+ pygame .constants .K_DOWN : Point (0 , - 1 ), \
23
+ pygame .constants .K_LEFT : Point (1 , 0 ), \
24
+ pygame .constants .K_RIGHT : Point (- 1 , 0 )}
25
+ self .arrowKeyMovementSpeed = 32
16
26
17
27
self .drawGrid = True
18
28
@@ -27,34 +37,41 @@ def __init__(self, game, imageCache, screenDimension):
27
37
def onKeyDown (self , key ):
28
38
if key == ord ('g' ):
29
39
self .drawGrid = not self .drawGrid
40
+ elif self .arrowKeyState .has_key (key ):
41
+ self .arrowKeyState [key ] = True
30
42
#
31
43
32
44
def onKeyUp (self , key ):
33
- pass
45
+ if self .arrowKeyState .has_key (key ):
46
+ self .arrowKeyState [key ] = False
34
47
#
35
48
36
49
def onMouseDown (self , button , position ):
37
50
if button == 3 : # Right mouse button, TODO: Look for pygame constants for this?
38
51
self .cameraMouseOffset .x = self .camera .x - position [0 ]
39
52
self .cameraMouseOffset .y = self .camera .y - position [1 ]
40
- self .rightMouseButtonDown = True
53
+ self .cameraDragging = True
41
54
#
42
55
43
56
def onMouseUp (self , button , position ):
44
57
if button == 3 :
45
- self .rightMouseButtonDown = False
58
+ self .cameraDragging = False
46
59
#
47
60
48
61
def onMouseMove (self , position ):
49
- if self .rightMouseButtonDown :
62
+ if self .cameraDragging :
50
63
self .camera .x = position [0 ] + self .cameraMouseOffset .x
51
64
self .camera .y = position [1 ] + self .cameraMouseOffset .y
52
65
53
66
self .clampCameraToLevel ()
54
67
#
55
68
56
69
def update (self ):
57
- pass
70
+ if not self .cameraDragging :
71
+ for key in self .arrowKeyState .keys ():
72
+ if self .arrowKeyState [key ]:
73
+ self .camera += self .arrowKeyMovement [key ] * self .arrowKeyMovementSpeed
74
+ self .clampCameraToLevel ()
58
75
#
59
76
60
77
def draw (self , screen ):
0 commit comments