From 5a0256d60df84bbebebe6a6a8687e2a1e0b3ca60 Mon Sep 17 00:00:00 2001 From: Jason Hilder Date: Mon, 3 Aug 2026 06:39:28 +0200 Subject: [PATCH] Testing basic basic attack animation on player. --- assets/textures/player/player_attack_one.png | Bin 0 -> 847 bytes assets/textures/player/player_idle.png | Bin 1054 -> 769 bytes assets/textures/player/player_walk.png | Bin 1409 -> 1029 bytes src/animator.odin | 4 +-- src/asset_manager.odin | 6 +++- src/main.odin | 4 +-- src/player.odin | 28 +++++++------------ 7 files changed, 19 insertions(+), 23 deletions(-) create mode 100644 assets/textures/player/player_attack_one.png diff --git a/assets/textures/player/player_attack_one.png b/assets/textures/player/player_attack_one.png new file mode 100644 index 0000000000000000000000000000000000000000..97e0da74df6a2b89ecd5556a15054abd0868d2ba GIT binary patch literal 847 zcmV-V1F-ywP)Px&2}wjjRCt{2oJrEFAP|7z)jL79<_d8CbI29UHdo-^sD%WTp@nYfugZ-hJwt0E z1j8^4!!QiPFbu;m48t%C!!QiPFr6U*?qMIeC&Mrm$PHFM=%Me=&}8&tKu-SD0mcS? z>2oMS&gj65UJOXfA3Lbrz|Vaic1Rl?h|!Bd7xI@5=AZ;?t&mbe+!rfd7`>3ui$PcN z|8G42B9t0^yB>wn3pta)It3u+e5!OMe{up)O6|d5j5!<&2;U1`8J%G^k`jO${DEV_ z7}KTWTWf=IpC!Dr^J9@jGihkpUcn$KS1c6e|5tLcQfl9N<|-gVhqTuFmV;f%y0{%u z2qCY0;i`ai07?0yX8;%nUz05fxPj@$=vj`?T8nv}v!1yLMc&Vi;<`$!06S#6s@(89=Z3zygXQ) z`=>el6uur?>!!B+AyRcv)B_NKHvyxOYxL5D(AwEcfGj8>-C@_ulLa-jRK21&0k{}r zc(!oDonCrN1T_l-#w5_PFs3AdLjtfTqz+)3ChKmg*HZ<;=oHqmA-0)ND_SRk*7Ezr zCV@i&2r2RERTd_JTY$~zqeC@$w&dq6fUm@yDgEd38P*Wr@Aqfl>-B0fmRKMv<@@~>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e|7taP!L)-a* z1MUA+snl`)rk(>#OidF@U*cx9YA(LPaG1exn9XvTsN)3sG|;vmV0q<^`TT2jo6T~W z&2l*?U0eJA+y0&CZ)yan&%1uSk|7cM8-R!t1>nVjm-z6@9|FGvSoBlxSf`JN%#KF? z*r(srcL()qvig1YH(RLC@YuOO65_Wj7XWzo>u>8{LRvX*r}(MAh4?@Ipx?_^zfJ%6 z=%@gaa$QNeu34IT({Til+V9n`{*Lf_eHDU7oj6l0GCn#=ZfWU}$L5xneCv(sSAP(G zPX!*PSNqWj>Q{eIe$U0VQbf>q0QIZ?u>PhC^iqhQ|G4_q-%fr-Q4~c{6h%=KMd?`n Y0oc!oyE&s*V*mgE07*qoM6N<$f-U3=y#N3J diff --git a/assets/textures/player/player_walk.png b/assets/textures/player/player_walk.png index 105f2fa3799fc96071c819ef4c1080ce0038bb50..0fb9a22596ecfd34e330f8efdd3e0cbe3fa89c79 100644 GIT binary patch delta 995 zcmV<9104K;3xx=fFngLM z5O#F`l6m1=ArKhz08}cKN~Kb%R4SE9rBbO>D%GuJ2-@%rZK_nN4r-mO>7=J_zedsp zNcqaYEWg$)cH*DqQ2F3WhVqqv3qICh>%?#6QTw1ugz}YtD}O%ug!JBnF-B^|FNyn+ zNBPRX6#p+#!`wRRxLyTF`O3c~zqtTBpHB|};GFyVo<8<1Gbm-N?k&wfy{czxAqgzA zKV@e4tUh8L6+q?F^ELl`{Hh(mULu~)XZ+DS=ei|7@S{%X*6|1G@(L*9;db$B{;NDx z^U*&jB_gPI0e|4;rz-j3=9fHh@-ey4{9h~os2u<@@iknOYLm~c5&TGbkl>Ec-?2vU zL+yd&Er8_Y?{yG_sQg`gNO+J~05t#gYVlAk01bhAYb^i(%=65;9U7t2VIUt;l8S$n zejmk0i>`7HV53Z@uLTH*icsY#v-SDZ{ zSId9R_&-$uj*{>zEB}$=B@A$mt;$e=iS`>{0Vy!*1RI6oU6$??k6*D&97v?D&=<$dUM(Z79`M)Yb)n;VSH^ z&ugx%FMm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Z4s+GlwCi|d*!T3KR1pA2_WI=NpAUdNH^f6k28{)}t=yaL=ySMy>JjDE27?-hexfV(w6)mz$r#-MWi z3!VXZA?^mFA6)%nZ9sl$tJHTLU_ODUn1UJoVC(BHKsRyhr|~!cN!PHi&|QEAgTY`h k7z_r3!C){L4EvFP0O%CHOrF9`%>V!Z07*qoM6N<$g3vw00{{R3 diff --git a/src/animator.odin b/src/animator.odin index 72c83c5..ed2fd4d 100644 --- a/src/animator.odin +++ b/src/animator.odin @@ -18,9 +18,9 @@ AnimationState :: struct { finished: bool, } -animation_play :: proc(state: ^AnimationState, clip: ^AnimationClip) { +animation_play :: proc(state: ^AnimationState, clip: ^AnimationClip, restart := false) { // already playing, do not reset - if state.clip == clip do return + if state.clip == clip && !restart do return state.clip = clip state.current_frame = 0 state.timer = 0 diff --git a/src/asset_manager.odin b/src/asset_manager.odin index 358187a..803dffc 100644 --- a/src/asset_manager.odin +++ b/src/asset_manager.odin @@ -32,13 +32,17 @@ asset_manager_init :: proc() -> Asset_Manager { init_player_assets :: proc(clip_array: ^[Player_State]AnimationClip) { idle_tex := rl.LoadTexture("assets/textures/player/player_idle.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 { - 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 { 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) { diff --git a/src/main.odin b/src/main.odin index 85b868f..9ab02fa 100644 --- a/src/main.odin +++ b/src/main.odin @@ -12,14 +12,14 @@ WINDOW_WIDTH :: 1920 WINDOW_HEIGHT :: 1080 GAME_WIDTH :: 480 GAME_HEIGHT :: 270 -MAX_ENEMIES :: 300 +MAX_ENEMIES :: 0 MAX_PROPS :: 64 TILE_SIZE :: 32 // ----------------------------------------------------------------------------- main :: proc() { - context.logger = log.create_console_logger() + context.logger = log.create_console_logger() defer log.destroy_console_logger(context.logger) when DEBUG_MODE { diff --git a/src/player.odin b/src/player.odin index 3c33fa9..e23753d 100644 --- a/src/player.odin +++ b/src/player.odin @@ -128,28 +128,21 @@ update_player :: proc( player.velocity.y = 0 } - // @TESTING - if rl.IsMouseButtonPressed(.LEFT) { - mouse_pos := rl.GetMousePosition() - screen_space := window_to_screen(mouse_pos) + if is_attacking { + player.velocity = rl.Vector2MoveTowards(player.velocity, rl.Vector2{0,0}, player.friction * dt) + } - x := screen_to_world(screen_space, camera) - fmt.printf("Mouse pos -> world pos: %v\n", x) - v := world_to_screen(x, camera) - fmt.printf("world pos -> screen pos: %v\n", v) - y := world_to_grid(x) - fmt.printf("Mouse pos -> grid coord: %v\n", y) - 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]) + if attack_pressed { + player.state = .ATTACK + animation_play(&player.animation, &assets.clips[.ATTACK], restart = true) + } else if !is_attacking { + player.state = moving ? .WALK : .IDLE + animation_play(&player.animation, &assets.clips[player.state]) + } animation_update(&player.animation, dt) } update_player_flow_field :: proc(player: ^Player, game_map: ^Game_Map) { - // Use the collider's center (not the sprite anchor/top-left) so the // grid cell reflects where the player physically is 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) { clip := player.animation.clip src_rect := animation_frame_rect(&player.animation)