gameplay prototype
This commit is contained in:
+5
-5
@@ -1,7 +1,6 @@
|
||||
package main
|
||||
|
||||
import "core:fmt"
|
||||
import "ecs"
|
||||
import rl "vendor:raylib"
|
||||
|
||||
World :: struct {
|
||||
@@ -15,7 +14,6 @@ camera: rl.Camera2D
|
||||
CELL_SIZE :: 20
|
||||
|
||||
main :: proc() {
|
||||
ecs.ping()
|
||||
fmt.println("hello world")
|
||||
rl.InitWindow(800, 600, "grimm gameplay prototype")
|
||||
defer rl.CloseWindow()
|
||||
@@ -59,6 +57,7 @@ update :: proc() {
|
||||
move(&enemy.transform, 1, 0)
|
||||
}
|
||||
|
||||
run_timers()
|
||||
}
|
||||
|
||||
draw :: proc() {
|
||||
@@ -77,7 +76,6 @@ draw :: proc() {
|
||||
rl.BLUE,
|
||||
)
|
||||
|
||||
|
||||
for x in 0 ..< 26 {
|
||||
for y in 0 ..< 26 {
|
||||
rl.DrawRectangleLines(
|
||||
@@ -90,11 +88,13 @@ draw :: proc() {
|
||||
}
|
||||
}
|
||||
|
||||
if rl.IsMouseButtonDown(rl.MouseButton.LEFT) {
|
||||
if rl.IsMouseButtonPressed(rl.MouseButton.LEFT) {
|
||||
pos := rl.GetScreenToWorld2D(rl.GetMousePosition(), player.camera)
|
||||
pos_x := int(pos.x / CELL_SIZE) * CELL_SIZE
|
||||
pos_y := int(pos.y / CELL_SIZE) * CELL_SIZE
|
||||
shoot({f32(pos_x), f32(pos_y)}, player.transform)
|
||||
shoot(player.transform, {f32(pos_x), f32(pos_y)})
|
||||
}
|
||||
|
||||
run_particle_system()
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package main
|
||||
|
||||
import "core:rexcode/isa/x86/tablegen/generated"
|
||||
import rl "vendor:raylib"
|
||||
|
||||
Particle :: union {
|
||||
SpriteParticle,
|
||||
LineParticle,
|
||||
}
|
||||
|
||||
SpriteParticle :: struct {
|
||||
pos: rl.Vector2,
|
||||
texture: rl.Texture2D,
|
||||
tint: rl.Color,
|
||||
lifetime: f32,
|
||||
}
|
||||
LineParticle :: struct {
|
||||
pos1: rl.Vector2,
|
||||
pos2: rl.Vector2,
|
||||
tint: rl.Color,
|
||||
lifetime: f32,
|
||||
}
|
||||
|
||||
particles: [dynamic]Particle
|
||||
|
||||
spawn_particle :: proc(particle: Particle) {
|
||||
append(&particles, particle)
|
||||
}
|
||||
|
||||
run_particle_system :: proc() {
|
||||
for &p, i in particles {
|
||||
draw_particle(&p, i)
|
||||
}
|
||||
}
|
||||
|
||||
draw_particle :: proc(particle: ^Particle, index: int) {
|
||||
switch &p in particle {
|
||||
case SpriteParticle:
|
||||
draw_sprite_particle(&p, index)
|
||||
|
||||
case LineParticle:
|
||||
draw_line_particle(&p, index)
|
||||
}
|
||||
}
|
||||
|
||||
draw_sprite_particle :: proc(particle: ^SpriteParticle, index: int) {
|
||||
rl.DrawTexture(particle.texture, i32(particle.pos.x), i32(particle.pos.y), particle.tint)
|
||||
particle.lifetime -= rl.GetFrameTime()
|
||||
if particle.lifetime <= 0 {
|
||||
particles[index] = nil
|
||||
}
|
||||
}
|
||||
|
||||
draw_line_particle :: proc(particle: ^LineParticle, index: int) {
|
||||
rl.DrawLineV(particle.pos1, particle.pos2, particle.tint)
|
||||
particle.lifetime -= rl.GetFrameTime()
|
||||
if particle.lifetime <= 0 {
|
||||
particles[index] = nil
|
||||
}
|
||||
}
|
||||
+14
-8
@@ -1,5 +1,6 @@
|
||||
package main
|
||||
|
||||
import "core:fmt"
|
||||
import rl "vendor:raylib"
|
||||
|
||||
move :: proc(t: ^Transform, x, y: f32) {
|
||||
@@ -13,16 +14,21 @@ move :: proc(t: ^Transform, x, y: f32) {
|
||||
}
|
||||
}
|
||||
|
||||
shoot :: proc(pos: rl.Vector2, t: Transform) {
|
||||
shoot :: proc(t: Transform, pos: rl.Vector2) {
|
||||
pos_centered := center_to_grid(pos)
|
||||
t_centered := center_to_grid(t.position)
|
||||
rl.DrawLine(
|
||||
i32(t.position.x) * CELL_SIZE + (CELL_SIZE / 2),
|
||||
i32(t.position.y) * CELL_SIZE + (CELL_SIZE / 2),
|
||||
i32(pos_centered.x),
|
||||
i32(pos_centered.y),
|
||||
rl.WHITE,
|
||||
)
|
||||
line_particle := LineParticle {
|
||||
pos1 = t.position * CELL_SIZE + 10,
|
||||
pos2 = pos + 10,
|
||||
tint = rl.WHITE,
|
||||
lifetime = 0.2,
|
||||
}
|
||||
spawn_particle(line_particle)
|
||||
start_timer(1, test_timer_callback)
|
||||
}
|
||||
|
||||
test_timer_callback :: proc() {
|
||||
fmt.println("timer finished")
|
||||
}
|
||||
|
||||
center_to_grid :: proc(pos: rl.Vector2) -> rl.Vector2 {
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package main
|
||||
|
||||
import rl "vendor:raylib"
|
||||
|
||||
Timer :: struct {
|
||||
lifetime: f32,
|
||||
callback: proc(),
|
||||
}
|
||||
|
||||
timers: [dynamic]Timer
|
||||
|
||||
start_timer :: proc(time: f32, callback: proc()) {
|
||||
new_timer := Timer {
|
||||
lifetime = time,
|
||||
callback = callback,
|
||||
}
|
||||
append(&timers, new_timer)
|
||||
}
|
||||
|
||||
run_timers :: proc() {
|
||||
for &t, i in timers {
|
||||
t.lifetime -= rl.GetFrameTime()
|
||||
if t.lifetime <= 0 {
|
||||
unordered_remove(&timers, i)
|
||||
t.callback()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user