~gustav-hartvigsson/+junk/invaders_vala

« back to all changes in this revision

Viewing changes to src/GameObject.vala

  • Committer: Gustav Hartvigsson
  • Date: 2012-10-09 21:59:24 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20121009215924-bsntg7a4ocaxkhoh
Implimented Time based movement...

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
using SDLImage;
4
4
 
5
5
namespace invadersGame{
6
 
  public SDL.Surface GameObjectImage;
7
6
  
8
7
  class GameObject : Object{
 
8
    
 
9
    protected SDL.Rect my_rect;
 
10
    
 
11
    protected float speed;
 
12
    protected float pos_x;
 
13
    protected float pos_y;
 
14
    protected uint32 last_frame;
 
15
    
9
16
    public struct MovmentVector {
10
17
      /** MovmentVector
11
18
       * Is used for storting a movement vector.
12
19
       * IE: if it should move up (y < 0), up (y > 0), left (x < 0),
13
20
       * right (x > 0).
14
21
       */
15
 
      int x;
16
 
      int y;
17
 
      int Speed; /* Maximum movement over Time */
18
 
      int Time; /* The time it takes to move */
 
22
      int delta_x; /* The delta of the object can have thee states:
 
23
                    delta_x < 0,  delta_x = 0  or delta_x > 0*/
 
24
      int delta_y; /* See above */
 
25
      int speed; /* Maximum movement over Time (in seconds) */
19
26
    } //MovmentVector
20
27
    
 
28
    int health; /* HP */
 
29
    
21
30
    MovmentVector mMovmentVector;
22
31
    
23
 
    public GameObject(){
24
 
      GameObjectImage = SDLImage.load("media/images/null.png");
25
 
      mMovmentVector = {
26
 
                  Game.getRandom(SCREEN_WIDTH),
27
 
                  Game.getRandom(SCREEN_HEIGHT),
28
 
                  0,
29
 
                  0
30
 
                  };
31
 
      stdout.printf("X: %i, Y: %i\n", mMovmentVector.x, mMovmentVector.y);
32
 
      
33
 
      mMovmentVector.x = 10;
34
 
      
35
 
      stdout.printf("New X: %i, Y: %i\n", mMovmentVector.x, mMovmentVector.y);
36
 
    }
37
 
    
 
32
    public GameObject(int16 x, int16 y, int delta_x, int delta_y,
 
33
                      int speed, int health){
 
34
      
 
35
      my_rect = SDL.Rect ();
 
36
      my_rect.x = x;
 
37
      my_rect.y = y;
 
38
      pos_x = x;
 
39
      pos_y = y;
 
40
      
 
41
      this.speed = speed;
 
42
      last_frame = SDL.Timer.get_ticks();
 
43
    }
 
44
    
 
45
    public virtual void draw(SDL.Screen screen) {
 
46
      ResourceHandler.image_null.blit(null ,screen,my_rect);
 
47
    }
 
48
    
 
49
    public virtual void move() {
 
50
      // Do nothing!
 
51
    }
38
52
  }
39
53
}
 
54
 
 
55
 
 
56
 
 
57
 
 
58