basic player move init, lesson #1
This commit is contained in:
parent
9866eae1b8
commit
69d8f66e22
4 changed files with 48 additions and 10 deletions
Binary file not shown.
4
build.c
4
build.c
|
@ -24,6 +24,6 @@ typedef struct Context_Extra {
|
||||||
//
|
//
|
||||||
// Comment & Uncomment to swap projects
|
// Comment & Uncomment to swap projects
|
||||||
|
|
||||||
#include "entry_engine_test.c"
|
// #include "entry_engine_test.c"
|
||||||
// #include "entry_minimal_example.c"
|
// #include "entry_minimal_example.c"
|
||||||
// #include "entry_randygame.c"
|
#include "entry_randygame.c"
|
|
@ -6,20 +6,58 @@ int entry(int argc, char **argv) {
|
||||||
window.height = 720;
|
window.height = 720;
|
||||||
window.x = 200;
|
window.x = 200;
|
||||||
window.y = 200;
|
window.y = 200;
|
||||||
window.clear_color = v4(1, 1, 1, 1);
|
window.clear_color = hex_to_rgba(0x2a2d3aff);
|
||||||
|
|
||||||
|
Gfx_Image* player = load_image_from_disk(fixed_string("player.png"), get_heap_allocator());
|
||||||
|
assert(player, "fuckie wucky happen");
|
||||||
|
|
||||||
|
Vector2 player_pos = v2(0, 0);
|
||||||
|
float64 seconds_counter = 0.0;
|
||||||
|
s32 frame_count = 0;
|
||||||
|
|
||||||
|
float64 last_time = os_get_current_time_in_seconds();
|
||||||
while (!window.should_close) {
|
while (!window.should_close) {
|
||||||
reset_temporary_storage();
|
reset_temporary_storage();
|
||||||
|
|
||||||
|
float64 now = os_get_current_time_in_seconds();
|
||||||
|
float64 delta_t = now - last_time;
|
||||||
|
last_time = now;
|
||||||
|
|
||||||
os_update();
|
os_update();
|
||||||
|
|
||||||
float64 now = os_get_current_time_in_seconds();
|
if (is_key_just_pressed(KEY_ESCAPE)) {
|
||||||
Matrix4 hammer_xform = m4_scalar(1.0);
|
window.should_close = true;
|
||||||
hammer_xform = m4_rotate_z(hammer_xform, (f32)now);
|
}
|
||||||
hammer_xform = m4_translate(hammer_xform, v3(-.25f, -.25f, 0));
|
|
||||||
draw_rect_xform(hammer_xform, v2(.5f, .5f), COLOR_RED);
|
Vector2 input_axis = v2(0, 0);
|
||||||
|
if (is_key_down('A')) {
|
||||||
|
input_axis.x -= 1.0;
|
||||||
|
}
|
||||||
|
if (is_key_down('D')) {
|
||||||
|
input_axis.x += 1.0;
|
||||||
|
}
|
||||||
|
if (is_key_down('S')) {
|
||||||
|
input_axis.y -= 1.0;
|
||||||
|
}
|
||||||
|
if (is_key_down('W')) {
|
||||||
|
input_axis.y += 1.0;
|
||||||
|
}
|
||||||
|
input_axis = v2_normalize(input_axis);
|
||||||
|
|
||||||
|
player_pos = v2_add(player_pos, v2_mulf(input_axis, 5.0 * delta_t));
|
||||||
|
|
||||||
|
Matrix4 xform = m4_scalar(1.0);
|
||||||
|
xform = m4_translate(xform, v3(player_pos.x, player_pos.y, 0));
|
||||||
|
draw_image_xform(player, xform, v2(.5f, .5f), COLOR_RED);
|
||||||
|
|
||||||
gfx_update();
|
gfx_update();
|
||||||
|
seconds_counter += delta_t;
|
||||||
|
frame_count += 1;
|
||||||
|
if (seconds_counter > 1.0) {
|
||||||
|
log("fps: %i", frame_count);
|
||||||
|
seconds_counter = 0.0;
|
||||||
|
frame_count = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
BIN
player.png
Normal file
BIN
player.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 119 B |
Reference in a new issue