gameplay prototype
This commit is contained in:
+5
-5
@@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "core:fmt"
|
import "core:fmt"
|
||||||
import "ecs"
|
|
||||||
import rl "vendor:raylib"
|
import rl "vendor:raylib"
|
||||||
|
|
||||||
World :: struct {
|
World :: struct {
|
||||||
@@ -15,7 +14,6 @@ camera: rl.Camera2D
|
|||||||
CELL_SIZE :: 20
|
CELL_SIZE :: 20
|
||||||
|
|
||||||
main :: proc() {
|
main :: proc() {
|
||||||
ecs.ping()
|
|
||||||
fmt.println("hello world")
|
fmt.println("hello world")
|
||||||
rl.InitWindow(800, 600, "grimm gameplay prototype")
|
rl.InitWindow(800, 600, "grimm gameplay prototype")
|
||||||
defer rl.CloseWindow()
|
defer rl.CloseWindow()
|
||||||
@@ -59,6 +57,7 @@ update :: proc() {
|
|||||||
move(&enemy.transform, 1, 0)
|
move(&enemy.transform, 1, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
run_timers()
|
||||||
}
|
}
|
||||||
|
|
||||||
draw :: proc() {
|
draw :: proc() {
|
||||||
@@ -77,7 +76,6 @@ draw :: proc() {
|
|||||||
rl.BLUE,
|
rl.BLUE,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
for x in 0 ..< 26 {
|
for x in 0 ..< 26 {
|
||||||
for y in 0 ..< 26 {
|
for y in 0 ..< 26 {
|
||||||
rl.DrawRectangleLines(
|
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 := rl.GetScreenToWorld2D(rl.GetMousePosition(), player.camera)
|
||||||
pos_x := int(pos.x / CELL_SIZE) * CELL_SIZE
|
pos_x := int(pos.x / CELL_SIZE) * CELL_SIZE
|
||||||
pos_y := int(pos.y / 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
|
package main
|
||||||
|
|
||||||
|
import "core:fmt"
|
||||||
import rl "vendor:raylib"
|
import rl "vendor:raylib"
|
||||||
|
|
||||||
move :: proc(t: ^Transform, x, y: f32) {
|
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)
|
pos_centered := center_to_grid(pos)
|
||||||
t_centered := center_to_grid(t.position)
|
t_centered := center_to_grid(t.position)
|
||||||
rl.DrawLine(
|
line_particle := LineParticle {
|
||||||
i32(t.position.x) * CELL_SIZE + (CELL_SIZE / 2),
|
pos1 = t.position * CELL_SIZE + 10,
|
||||||
i32(t.position.y) * CELL_SIZE + (CELL_SIZE / 2),
|
pos2 = pos + 10,
|
||||||
i32(pos_centered.x),
|
tint = rl.WHITE,
|
||||||
i32(pos_centered.y),
|
lifetime = 0.2,
|
||||||
rl.WHITE,
|
}
|
||||||
)
|
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 {
|
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