Bladeren bron

Hero sprite and her life/magi bars

volt 1 jaar geleden
bovenliggende
commit
6762ecea0c

+ 3 - 0
objects/obj_fight_scn/Create_0.gml

@@ -42,3 +42,6 @@ for (mob_i=0; mob_i<mobs_nb; mob_i++;)
 		x = _mobs_leftmost + _relative_x;
 	}
 }
+
+// Spawn Hero
+instance_create_depth(0, 0, 40, obj_player);

+ 2 - 0
objects/obj_game/Create_0.gml

@@ -2,6 +2,8 @@
 
 set_fps = 60;
 
+randomize();
+
 game_set_speed(60, gamespeed_fps);
 show_debug_overlay(true);
 

+ 17 - 0
objects/obj_game/obj_game.yy

@@ -1,2 +1,19 @@
 /// @description init
 
+image_xscale = 0.15;
+image_yscale = 0.15;
+
+x = room_width - (sprite_width - 100);
+y = room_height - (sprite_height/2.3);
+
+//draw_self();
+
+lifemax = 10
+magimax = 10
+life = 10
+magi = 8
+
+// Life and Magi bars dimensions
+_bar_w = 90;
+_bar_h = 20;
+_bar_inset = 3;

+ 14 - 0
objects/obj_player/Draw_64.gml

@@ -0,0 +1,14 @@
+/// @description UI
+
+draw_set_alpha(1);
+draw_set_color(c_white);
+draw_rect(x, y, _bar_w, _bar_h, true);
+draw_set_color(c_lime);
+var _lifebar = progressbar(life, lifemax, _bar_w);
+draw_rect_inset(x, y, _lifebar, _bar_h, _bar_inset);
+
+draw_set_color(c_white);
+draw_rect(x, y+40, _bar_w, _bar_h, true);
+draw_set_color(c_aqua);
+var _magibar = progressbar(magi, magimax, _bar_w);
+draw_rect_inset(x, y+40, _magibar, _bar_h, _bar_inset);

+ 1 - 0
objects/obj_player/Step_0.gml

@@ -0,0 +1 @@
+/// @description step

+ 6 - 1
objects/obj_player/obj_player.yy

@@ -3,6 +3,8 @@
   "%Name":"obj_player",
   "eventList":[
     {"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":0,"eventType":0,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
+    {"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":64,"eventType":8,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
+    {"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":0,"eventType":3,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
   ],
   "managed":true,
   "name":"obj_player",
@@ -29,7 +31,10 @@
   "resourceType":"GMObject",
   "resourceVersion":"2.0",
   "solid":false,
-  "spriteId":null,
+  "spriteId":{
+    "name":"spr_ranger",
+    "path":"sprites/spr_ranger/spr_ranger.yy",
+  },
   "spriteMaskId":null,
   "visible":true,
 }

+ 41 - 0
scripts/scr_toolset/scr_toolset.gml

@@ -20,4 +20,45 @@ function array_loop(_arr, _curr, _add){
 	}
 		
 	return _curr
+}
+
+
+// @function							progressbar();
+/// @param {real}		_curr			Current value
+/// @param {real}		_max			Max value
+/// @param {real}		_width			Max width (in pixels) of bar
+/// @description						Draw current width of a progress bar
+function progressbar(_curr, _max, _width){
+	return (_width / _max) * _curr
+}
+
+// @function							draw_rect();
+/// @param {real}		_x				x pos
+/// @param {real}		_y				y pos
+/// @param {real}		_width			rect width
+/// @param {real}		_height			rect height
+/// @param {boolean}	_outline		With outline?
+/// @description						Draw a rectangle from width and height
+function draw_rect(_x, _y, _width, _height, _outline){
+	var _x2 = (_x + _width);
+	var _y2 = (_y + _height);
+	
+	draw_rectangle(_x, _y, _x2, _y2, _outline);
+}
+
+// @function							draw_rect_inset();
+/// @param {real}		_x				x pos
+/// @param {real}		_y				y pos
+/// @param {real}		_width			rect width
+/// @param {real}		_height			rect height
+/// @param {real}		_inset			how much of inset
+/// @description						Draw a rectangle from width and height (and opt. inset)
+function draw_rect_inset(_x, _y, _width, _height, _inset = 0){
+	var _x1 = _x + _inset;
+	var _x2 = (_x + _width) - _inset;
+	
+	var _y1 = _y + _inset;
+	var _y2 = (_y + _height) - _inset;
+	
+	draw_rectangle(_x1, _y1, _x2, _y2, false);
 }