Init project
This commit is contained in:
commit
195b54835c
109
game.odin
Normal file
109
game.odin
Normal file
@ -0,0 +1,109 @@
|
||||
package game
|
||||
|
||||
import rl "vendor:raylib"
|
||||
import "core:math"
|
||||
import "core:math/rand"
|
||||
import "core:fmt"
|
||||
|
||||
Vec2 :: [2]f32
|
||||
Rect :: rl.Rectangle
|
||||
Img :: rl.Image
|
||||
Tex :: rl.Texture
|
||||
Key :: rl.KeyboardKey
|
||||
|
||||
SCREEN_WIDTH : i32 = 1000
|
||||
SCREEN_HEIGHT : i32 = 800
|
||||
BW := f32(SCREEN_WIDTH)
|
||||
BH := f32(SCREEN_HEIGHT)
|
||||
|
||||
BULLET_SPEED : f32 = 7.5
|
||||
BULLET_RADIUS : f32 = 5
|
||||
|
||||
ANGULAR_SPEED : f32 = 0.045
|
||||
THRUST_SPEED : f32 = 2.3
|
||||
|
||||
Player :: struct {
|
||||
pos: Vec2,
|
||||
points: [4]Vec2,
|
||||
angle: f32,
|
||||
vel: Vec2
|
||||
}
|
||||
|
||||
Bullet :: struct {
|
||||
pos: Vec2,
|
||||
vel: Vec2,
|
||||
}
|
||||
|
||||
GameState :: struct {
|
||||
dt: f32,
|
||||
keymap: map[string]Key,
|
||||
player: Player,
|
||||
bullets: [dynamic]Bullet,
|
||||
}
|
||||
|
||||
init_state :: proc() -> ^GameState {
|
||||
keymap := make(map[string]Key)
|
||||
keymap["Left"] = .A
|
||||
keymap["Right"] = .D
|
||||
keymap["Up"] = .W
|
||||
keymap["Down"] = .S
|
||||
|
||||
state := GameState {
|
||||
keymap = keymap,
|
||||
}
|
||||
cloned := new_clone(state)
|
||||
return cloned
|
||||
}
|
||||
|
||||
player_input :: proc(using s: ^GameState) {
|
||||
if rl.IsKeyDown(.D) {
|
||||
player.angle += ANGULAR_SPEED
|
||||
}
|
||||
if rl.IsKeyDown(.A) {
|
||||
player.angle -= ANGULAR_SPEED
|
||||
}
|
||||
if rl.IsKeyDown(.W) {
|
||||
player.vel.x += math.cos(player.angle)
|
||||
player.vel.y += math.sin(player.angle)
|
||||
}
|
||||
if rl.IsKeyPressed(.SPACE) {
|
||||
b_vel := Vec2{ math.cos(player.angle) , math.sin(player.angle) } * BULLET_SPEED
|
||||
append(&s.bullets, Bullet{player.points[0], b_vel})
|
||||
}
|
||||
}
|
||||
|
||||
update :: proc(using s: ^GameState) {
|
||||
player.pos += player.vel * (THRUST_SPEED * s.dt)
|
||||
}
|
||||
|
||||
draw :: proc(using s: ^GameState) {
|
||||
rl.DrawCircleV(player.pos, 10, rl.BLACK)
|
||||
rect := Rect{player.pos.x, player.pos.y, 20, 5}
|
||||
rl.DrawRectanglePro(rect, Vec2{0,2.5}, player.angle * rl.RAD2DEG, rl.BLACK)
|
||||
}
|
||||
|
||||
main :: proc() {
|
||||
rl.SetTraceLogLevel(.ERROR)
|
||||
rl.InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "F&M")
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
state := init_state()
|
||||
defer free(state)
|
||||
|
||||
for !rl.WindowShouldClose() {
|
||||
state.dt = rl.GetFrameTime()
|
||||
|
||||
player_input(state)
|
||||
|
||||
update(state)
|
||||
|
||||
rl.BeginDrawing()
|
||||
rl.ClearBackground(rl.WHITE)
|
||||
|
||||
draw(state)
|
||||
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
rl.CloseWindow()
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user