Commit 6b97de79 authored by David Quiroga's avatar David Quiroga
Browse files

Clean input and change method name in gameloop

parent 11ef2e6a
......@@ -27,7 +27,7 @@ public class GSDL.GameLoop : Object {
SGP.Utils.renderer = wsdl.renderer;
this.rand = new GLib.Rand ();
load_resources ();
create_messages ();
create_shapes ();
}
~GameLoop () {
......@@ -37,10 +37,12 @@ public class GSDL.GameLoop : Object {
jetmono = RFont.load_font_file ("JetMono-EB.ttf", 30);
}
private void create_messages () {
private void create_shapes () {
msg_mouse_left = new RFont (wsdl, jetmono);
msg_mouse_right = new RFont (wsdl, jetmono);
//SGP.Utils.smooth = false;
msg_mouse_left.set_text_blended ("left click changes the shapes", 600);
msg_mouse_right.set_text_blended ("right click changes the cursor", 600);
line_c = new Line2D (new Point2D (150, 300), new Point2D (250, 350));
circle_c = new Circle2D (new Point2D (400, 400), 40);
rectangle_c = new Rectangle2D (new Point2D (100, 100),
......@@ -114,8 +116,6 @@ public class GSDL.GameLoop : Object {
}
private void update () {
msg_mouse_left.set_text_blended ("left click changes the shapes", 600);
msg_mouse_right.set_text_blended ("right click changes the cursor", 600);
if (input.mouse_button_1 == true)
reset ();
if (input.mouse_button_3 == true)
......
using SDL;
public class GSDL.Input : Object {
private const int MAX_KEYBOARD_KEYS = 350;
private bool[] _akeys = {};
public bool done { get; private set; default = false; }
public SGP.Point2D vmouse;
public bool mouse_button_1 { get; private set; default = false; }
public bool mouse_button_3 { get; private set; default = false; }
public Input () {
this._akeys = new bool[MAX_KEYBOARD_KEYS];
this.vmouse = new SGP.Point2D.cero ();
}
public bool[] get_akeys () {
return this._akeys;
}
public void set_akey (int key, bool state) {
if (key < MAX_KEYBOARD_KEYS)
this._akeys[key] = state;
}
public void process_events () {
Event event;
......@@ -30,12 +18,6 @@ public class GSDL.Input : Object {
case EventType.QUIT:
this._done = true;
break;
case EventType.KEYDOWN:
this.on_keyboard_down (event.key);
break;
case EventType.KEYUP:
this.on_keyboard_up (event.key);
break;
case EventType.MOUSEMOTION:
this.mousemottion (event.motion);
break;
......@@ -51,18 +33,6 @@ public class GSDL.Input : Object {
}
}
private void on_keyboard_up (KeyboardEvent event) {
if (event.repeat == 0 && event.keysym.scancode < MAX_KEYBOARD_KEYS) {
this._akeys[event.keysym.scancode] = false;
}
}
private void on_keyboard_down (KeyboardEvent event) {
if (event.repeat == 0 && event.keysym.scancode < MAX_KEYBOARD_KEYS) {
this._akeys[event.keysym.scancode] = true;
}
}
private void mousemottion (MouseMotionEvent event) {
this.vmouse.x = event.x;
this.vmouse.y = event.y;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment