forked from galah4d/pacman-cx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.cx
More file actions
90 lines (77 loc) · 2.26 KB
/
player.cx
File metadata and controls
90 lines (77 loc) · 2.26 KB
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
package main
// constants
var PLAYER_COLOR_RED f32 = 1.0
var PLAYER_COLOR_GREEN f32 = 1.0
var PLAYER_COLOR_BLUE f32 = 0.0
var PLAYER_RADIUS f32 = 0.025
var PLAYER_SPAWN_LINE i32 = 23
var PLAYER_SPAWN_COLUMN i32 = 13
// vars
var SCORE i32 = 0
var PLAYER_LIVES i32 = 3
var nextLifePos graphical2d.Position2D
// structs
type Player struct {
position graphical2d.Position2D // 2D position (x, y) in world space
cell_pos graphical2d.Position2D // position in occupied cell's local space
color graphical2d.Color // RGB color (r, g, b)
radius f32
direction i32
speed f32
index_x i32
index_y i32
}
var player Player
/***************************************
* Declaration of constructor functions.
***************************************/
/* Function : newPlayer
Input : Spawn line (line i32)
: Spawn column (column i32)
: Radius (rad f32)
Output : player (pl Player)
Description : Constructor for the Player struct.
*/
func newPlayer (line i32, column i32, rad f32) (pl Player) {
var pos graphical2d.Position2D
pos = coords2position(line, column)
var col graphical2d.Color
col = graphical2d.newColor(PLAYER_COLOR_RED, PLAYER_COLOR_GREEN, PLAYER_COLOR_BLUE)
pl = Player{
position: pos,
//cell_pos: 0.0,
color: col,
radius: rad,
direction: LEFT,
speed: 0.4,
index_x: column,
index_y: line}
}
/* Function : movePlayer
Input : Direction in which the player should move (direction i32)
Description : Manages the player movement.
*/
func movePlayer(direction i32) {
if bool.eq(canMove(direction, player.index_y, player.index_x), true) {
// Moves
if direction == UP {
player.index_y = i32.sub(player.index_y, 1)
} else
if direction == DOWN {
player.index_y = i32.add(player.index_y, 1)
} else
if direction == LEFT {
player.index_x = i32.sub(player.index_x, 1)
} else
if direction == RIGHT {
player.index_x = i32.add(player.index_x, 1)
}
player.direction = direction
//player.position = coords2position(player.index_y, player.index_x)
}
// Check for collisions with ghosts
// FIX ME / FIXME: remove double collision check
for i:=0; i<4; i++ {
checkPlayerGhostCollision(ghosts[i])
}
}