Cleanup, rename player func and add map interaction.
This commit is contained in:
+2
-3
@@ -3,7 +3,7 @@ package game
|
||||
import "core:log"
|
||||
import "core:mem"
|
||||
|
||||
// Configuration Variables
|
||||
// Global Config Variables
|
||||
// -----------------------------------------------------------------------------
|
||||
DEBUG_MODE :: true
|
||||
|
||||
@@ -15,6 +15,7 @@ GAME_HEIGHT :: 270
|
||||
WINDOW_TITLE :: "Graveyard"
|
||||
PLAYER_SPEED :: 180
|
||||
TILE_SIZE :: 32
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
main :: proc() {
|
||||
context.logger = log.create_console_logger()
|
||||
@@ -51,5 +52,3 @@ main :: proc() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+16
-4
@@ -1,5 +1,6 @@
|
||||
package game
|
||||
|
||||
import "core:fmt"
|
||||
import rl "vendor:raylib"
|
||||
|
||||
Direction :: enum { LEFT, RIGHT }
|
||||
@@ -14,15 +15,14 @@ Player :: struct {
|
||||
|
||||
player_init :: proc(assets: ^Player_Assets) -> Player {
|
||||
player := Player{}
|
||||
// center for now not really needed
|
||||
player.pos = {(WINDOW_WIDTH / 2), (WINDOW_HEIGHT / 2)}
|
||||
player.pos = {320, 320}
|
||||
player.state = .IDLE
|
||||
animation_play(&player.ani_state, &assets.clips[.IDLE])
|
||||
|
||||
return player
|
||||
}
|
||||
|
||||
update_player :: proc(player: ^Player, assets: ^Player_Assets) {
|
||||
update_player :: proc(player: ^Player, assets: ^Player_Assets, camera: rl.Camera2D) {
|
||||
moving := false
|
||||
dt := rl.GetFrameTime()
|
||||
|
||||
@@ -40,13 +40,25 @@ update_player :: proc(player: ^Player, assets: ^Player_Assets) {
|
||||
moving = true
|
||||
}
|
||||
|
||||
if rl.IsMouseButtonPressed(.LEFT) {
|
||||
pixel_pos := rl.GetMousePosition()
|
||||
//convert to render size
|
||||
pixel_pos.x = pixel_pos.x / (WINDOW_WIDTH / GAME_WIDTH)
|
||||
pixel_pos.y = pixel_pos.y / (WINDOW_HEIGHT / GAME_HEIGHT)
|
||||
|
||||
grid_space := world_to_grid(pixel_pos, camera)
|
||||
fmt.printf("GRID SPACE: %v\n", grid_space)
|
||||
world_space := grid_to_world(grid_space[0], grid_space[1])
|
||||
fmt.printf("WORLD SPACE: %v\n", world_space)
|
||||
}
|
||||
|
||||
player.state = moving ? .WALK : .IDLE
|
||||
|
||||
animation_play(&player.ani_state, &assets.clips[player.state])
|
||||
animation_update(&player.ani_state, dt)
|
||||
}
|
||||
|
||||
renderer_draw_player :: proc(player: ^Player) {
|
||||
draw_player :: proc(player: ^Player) {
|
||||
clip := player.ani_state.clip
|
||||
src_rect := animation_frame_rect(&player.ani_state)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user