Advertisement
weberc2

I guess I just don't understand Vala's parameter direction..

Apr 17th, 2013
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Vala 1.53 KB | None | 0 0
  1. namespace Game {
  2.     class Stage {
  3.         const int UNIT_H = 101;
  4.         const int UNIT_V = 82;
  5.         private Clutter.Stage _clStage;
  6.  
  7.         public Stage () {
  8.             _clStage = Clutter.Stage.get_default ();
  9.             AddTree (5,3);
  10.  
  11.             _clStage.color = Clutter.Color () { alpha = 255 };
  12.             _clStage.show_all ();
  13.         }
  14.  
  15.         public void AddDrawable (Drawable drawable) {
  16.             _clStage.add_actor (drawable);
  17.         }
  18.  
  19.         public void AddTree (int x, int y) {
  20.             AddDrawable (new Tree (x*UNIT_H, y*UNIT_V+UNIT_V/2));
  21.         }
  22.     }
  23.  
  24.  
  25.     class Drawable : Clutter.Actor {
  26.         private Cairo.ImageSurface _surface;
  27.  
  28.         public Drawable (float x, float y, float width, float height, string filepath) {
  29.             this.x = x;
  30.             this.y = y;
  31.             this.width = width;
  32.             this.height = height;
  33.  
  34.             var canvas = new Clutter.Canvas ();
  35.             set_content (canvas);
  36.             canvas.set_size ((int)width, (int)height);
  37.             canvas.draw.connect (drawme);
  38.  
  39.             _surface = new Cairo.ImageSurface.from_png (filepath);
  40.             canvas.invalidate ();
  41.         }
  42.        
  43.         private bool drawme (Cairo.Context ctx, int w, int h) {
  44.             ctx.set_source_surface (_surface, 0, 0);
  45.             ctx.paint ();
  46.             return true;
  47.         }
  48.     }
  49.  
  50.     class GameObject : Drawable {
  51.         const int IMG_WIDTH = 101;
  52.         const int IMG_HEIGHT = 171;
  53.  
  54.         public GameObject (float x, float y, string filepath) {
  55.             base (x, y, IMG_WIDTH, IMG_HEIGHT, filepath);
  56.         }
  57.     }
  58.    
  59.     class Tree : GameObject {
  60.         const string IMG_PATH = "imgs/Tree Tall.png";
  61.         public Tree (float x, float y) {
  62.             base (x, y, IMG_PATH);
  63.         }
  64.     }
  65.    
  66.     void main (string[] args) {
  67.         stdout.printf ("HELLO");
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement