aboutsummaryrefslogtreecommitdiff
path: root/entities/player_entity.wren
blob: c547e4ef7ed4d1a065e20488fb9f40a66c42dfa4 (plain)
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
import "graphics" for ImageData, Canvas
import "./controls" for Controls
import "./config" for Config
class Player {
    construct new(x,y, gameState) {
        __gameState = gameState
        _x = x
        _y = y

        _playerSprite = ImageData.loadFromFile("assets/sprites/player.png")
    }

    x { _x }
    y { _y }
    w { 16 }
    h {  16 }

    update() {

        var collided = __gameState.checkCollision(this)
       
        if(Controls.isKeyDown(Config.KeyboardConstants["UP"]) && !collided) {
            _y = _y - 1
        } else if(Controls.isKeyDown(Config.KeyboardConstants["UP"]) && collided){
            _y = _y + 1
        }

        if(Controls.isKeyDown(Config.KeyboardConstants["DOWN"]) && !collided) {
            _y = _y + 1
        } else if(Controls.isKeyDown(Config.KeyboardConstants["DOWN"]) && collided){
            _y = _y - 1
        }

        if(Controls.isKeyDown(Config.KeyboardConstants["LEFT"]) && !collided) {
            _x = _x - 1
        } else if(Controls.isKeyDown(Config.KeyboardConstants["LEFT"]) && collided){
            _x = _x + 1
        }

        if(Controls.isKeyDown(Config.KeyboardConstants["RIGHT"]) && !collided) {
            _x = _x + 1
        } else if(Controls.isKeyDown(Config.KeyboardConstants["RIGHT"]) && collided){
            _x = _x - 1
        }


    }

    draw(dt) {
        Canvas.draw(_playerSprite,_x,_y)
    }

}