~brzeti/patat/dev

« back to all changes in this revision

Viewing changes to src/com/brackeen/javagamebook/tilegame/sprites/Player.java

  • Committer: Arthur Skonecki
  • Date: 2008-12-02 12:59:20 UTC
  • Revision ID: admin@adb.cba.pl-20081202125920-hmvdzcrxgq1tl514
initial project's files submission

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package com.brackeen.javagamebook.tilegame.sprites;
 
2
 
 
3
import com.brackeen.javagamebook.graphics.Animation;
 
4
import com.brackeen.javagamebook.util.MessagesSimple;
 
5
 
 
6
/**
 
7
    The Player.
 
8
*/
 
9
public class Player extends Creature {
 
10
 
 
11
    private static final float JUMP_SPEED = -.95f;
 
12
 
 
13
    public static boolean bGluedAllowed = true;
 
14
    private boolean onGround;
 
15
    private boolean bGodMode = false;
 
16
    
 
17
    public void setGodMode(boolean bool) {
 
18
        bGodMode = bool;
 
19
    }
 
20
 
 
21
    public Player(Animation left, Animation right,
 
22
        Animation deadLeft, Animation deadRight)
 
23
    {
 
24
        super(left, right, deadLeft, deadRight);
 
25
        MessagesSimple.getInstance().setTrackedSprite(this);
 
26
    }
 
27
 
 
28
 
 
29
    public void collideHorizontal() {
 
30
        setVelocityX(0);
 
31
    }
 
32
 
 
33
 
 
34
    public void collideVertical() {
 
35
        // check if collided with ground
 
36
        if (getVelocityY() > 0) {
 
37
            onGround = true;
 
38
        }
 
39
        setVelocityY(0);
 
40
    }
 
41
 
 
42
 
 
43
    public void setY(float y) {
 
44
        // check if falling
 
45
        if (Math.round(y) > Math.round(getY())) {
 
46
            onGround = false;
 
47
        }
 
48
        super.setY(y);
 
49
    }
 
50
 
 
51
 
 
52
    public void wakeUp() {
 
53
        // do nothing
 
54
    }
 
55
 
 
56
 
 
57
    /**
 
58
        Makes the player jump if the player is on the ground or
 
59
        if forceJump is true.
 
60
    */
 
61
    public void jump(boolean forceJump) {
 
62
        if (onGround || forceJump) {
 
63
            onGround = false;
 
64
            setVelocityY(JUMP_SPEED);
 
65
        }
 
66
    }
 
67
 
 
68
 
 
69
    public float getMaxSpeed() {
 
70
        return 0.5f;
 
71
    }
 
72
    
 
73
    public boolean isAlive() {
 
74
        if(bGodMode) return true;
 
75
        else return super.isAlive();
 
76
    }
 
77
    public void setState(int state) {
 
78
        if(bGodMode) return;
 
79
        else super.setState(state);
 
80
    }
 
81
    
 
82
    
 
83
}