Testing basic basic attack animation on player.
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 847 B |
Binary file not shown.
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 769 B |
Binary file not shown.
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.0 KiB |
+2
-2
@@ -18,9 +18,9 @@ AnimationState :: struct {
|
|||||||
finished: bool,
|
finished: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
animation_play :: proc(state: ^AnimationState, clip: ^AnimationClip) {
|
animation_play :: proc(state: ^AnimationState, clip: ^AnimationClip, restart := false) {
|
||||||
// already playing, do not reset
|
// already playing, do not reset
|
||||||
if state.clip == clip do return
|
if state.clip == clip && !restart do return
|
||||||
state.clip = clip
|
state.clip = clip
|
||||||
state.current_frame = 0
|
state.current_frame = 0
|
||||||
state.timer = 0
|
state.timer = 0
|
||||||
|
|||||||
@@ -32,13 +32,17 @@ asset_manager_init :: proc() -> Asset_Manager {
|
|||||||
init_player_assets :: proc(clip_array: ^[Player_State]AnimationClip) {
|
init_player_assets :: proc(clip_array: ^[Player_State]AnimationClip) {
|
||||||
idle_tex := rl.LoadTexture("assets/textures/player/player_idle.png")
|
idle_tex := rl.LoadTexture("assets/textures/player/player_idle.png")
|
||||||
walk_tex := rl.LoadTexture("assets/textures/player/player_walk.png")
|
walk_tex := rl.LoadTexture("assets/textures/player/player_walk.png")
|
||||||
|
attk_tex := rl.LoadTexture("assets/textures/player/player_attack_one.png")
|
||||||
|
|
||||||
clip_array[.IDLE] = AnimationClip {
|
clip_array[.IDLE] = AnimationClip {
|
||||||
texture = idle_tex, frame_count = 6, frame_width = 32, frame_height = 32, frame_time = 0.14, looping = true,
|
texture = idle_tex, frame_count = 8, frame_width = 32, frame_height = 32, frame_time = 0.14, looping = true,
|
||||||
}
|
}
|
||||||
clip_array[.WALK] = AnimationClip {
|
clip_array[.WALK] = AnimationClip {
|
||||||
texture = walk_tex, frame_count = 8, frame_width = 32, frame_height = 32, frame_time = 0.14, looping = true,
|
texture = walk_tex, frame_count = 8, frame_width = 32, frame_height = 32, frame_time = 0.14, looping = true,
|
||||||
}
|
}
|
||||||
|
clip_array[.ATTACK] = AnimationClip {
|
||||||
|
texture = attk_tex, frame_count = 4, frame_width = 64, frame_height = 32, frame_time = 0.12, looping = false,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
init_enemy_assets :: proc(clip_array: ^[Enemy_State]AnimationClip) {
|
init_enemy_assets :: proc(clip_array: ^[Enemy_State]AnimationClip) {
|
||||||
|
|||||||
+2
-2
@@ -12,14 +12,14 @@ WINDOW_WIDTH :: 1920
|
|||||||
WINDOW_HEIGHT :: 1080
|
WINDOW_HEIGHT :: 1080
|
||||||
GAME_WIDTH :: 480
|
GAME_WIDTH :: 480
|
||||||
GAME_HEIGHT :: 270
|
GAME_HEIGHT :: 270
|
||||||
MAX_ENEMIES :: 300
|
MAX_ENEMIES :: 0
|
||||||
MAX_PROPS :: 64
|
MAX_PROPS :: 64
|
||||||
TILE_SIZE :: 32
|
TILE_SIZE :: 32
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
main :: proc() {
|
main :: proc() {
|
||||||
context.logger = log.create_console_logger()
|
context.logger = log.create_console_logger()
|
||||||
defer log.destroy_console_logger(context.logger)
|
defer log.destroy_console_logger(context.logger)
|
||||||
|
|
||||||
when DEBUG_MODE {
|
when DEBUG_MODE {
|
||||||
|
|||||||
+10
-18
@@ -128,28 +128,21 @@ update_player :: proc(
|
|||||||
player.velocity.y = 0
|
player.velocity.y = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// @TESTING
|
if is_attacking {
|
||||||
if rl.IsMouseButtonPressed(.LEFT) {
|
player.velocity = rl.Vector2MoveTowards(player.velocity, rl.Vector2{0,0}, player.friction * dt)
|
||||||
mouse_pos := rl.GetMousePosition()
|
}
|
||||||
screen_space := window_to_screen(mouse_pos)
|
|
||||||
|
|
||||||
x := screen_to_world(screen_space, camera)
|
if attack_pressed {
|
||||||
fmt.printf("Mouse pos -> world pos: %v\n", x)
|
player.state = .ATTACK
|
||||||
v := world_to_screen(x, camera)
|
animation_play(&player.animation, &assets.clips[.ATTACK], restart = true)
|
||||||
fmt.printf("world pos -> screen pos: %v\n", v)
|
} else if !is_attacking {
|
||||||
y := world_to_grid(x)
|
player.state = moving ? .WALK : .IDLE
|
||||||
fmt.printf("Mouse pos -> grid coord: %v\n", y)
|
animation_play(&player.animation, &assets.clips[player.state])
|
||||||
z := grid_to_world(y[0], y[1])
|
}
|
||||||
fmt.printf("grid pos -> world pos: %v\n", z)
|
|
||||||
}
|
|
||||||
|
|
||||||
player.state = moving ? .WALK : .IDLE
|
|
||||||
animation_play(&player.animation, &assets.clips[player.state])
|
|
||||||
animation_update(&player.animation, dt)
|
animation_update(&player.animation, dt)
|
||||||
}
|
}
|
||||||
|
|
||||||
update_player_flow_field :: proc(player: ^Player, game_map: ^Game_Map) {
|
update_player_flow_field :: proc(player: ^Player, game_map: ^Game_Map) {
|
||||||
|
|
||||||
// Use the collider's center (not the sprite anchor/top-left) so the
|
// Use the collider's center (not the sprite anchor/top-left) so the
|
||||||
// grid cell reflects where the player physically is
|
// grid cell reflects where the player physically is
|
||||||
collider := get_player_collider(player, player.position)
|
collider := get_player_collider(player, player.position)
|
||||||
@@ -170,7 +163,6 @@ update_player_flow_field :: proc(player: ^Player, game_map: ^Game_Map) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
draw_player :: proc(player: ^Player) {
|
draw_player :: proc(player: ^Player) {
|
||||||
clip := player.animation.clip
|
clip := player.animation.clip
|
||||||
src_rect := animation_frame_rect(&player.animation)
|
src_rect := animation_frame_rect(&player.animation)
|
||||||
|
|||||||
Reference in New Issue
Block a user