瀏覽代碼

Small bug fixes

Karl Zylinski 6 月之前
父節點
當前提交
31edc5324a
共有 3 個文件被更改,包括 8 次插入4 次删除
  1. 5 4
      examples/snake/snake.odin
  2. 2 0
      karl2d.odin
  3. 1 0
      window_win32.odin

+ 5 - 4
examples/snake/snake.odin

@@ -171,14 +171,17 @@ main :: proc() {
 		k2.set_camera(camera)
 		food_sprite.width = CELL_SIZE
 		food_sprite.height = CELL_SIZE
-		k2.draw_texture(food_sprite, {f32(food_pos.x), f32(food_pos.y)}*CELL_SIZE)
 
 		time_since_food := time.duration_seconds(time.diff(food_eaten_at, time_now))
 
 		if time_since_food < 0.5 && total_time > 1 {
-			shader.input_overrides[3] = k2.create_vertex_input_override(k2.Vec2{f32(math.cos(total_time*100)), f32(math.sin(total_time*120 + 3))})
+			shader.input_overrides[3] = k2.create_vertex_input_override(k2.Vec2{f32(math.cos(total_time*100)*4), f32(math.sin(total_time*120 + 3)*4)})
 		}
 
+		k2.draw_texture(food_sprite, {f32(food_pos.x), f32(food_pos.y)}*CELL_SIZE)
+
+		shader.input_overrides[3] = {}
+
 		for i in 0..<snake_length {
 			part_sprite := body_sprite
 			dir: Vec2i
@@ -215,8 +218,6 @@ main :: proc() {
 			k2.draw_text("Press Enter to play again", {4, 30}, 15, k2.BLACK)
 		}
 
-		shader.input_overrides[3] = {}
-
 		score := snake_length - 3
 		score_str := fmt.tprintf("Score: %v", score)
 		k2.draw_text(score_str, {4, CANVAS_SIZE - 14}, 10, k2.GRAY)

+ 2 - 0
karl2d.odin

@@ -488,6 +488,8 @@ _batch_vertex :: proc(v: Vec2, uv: Vec2, color: Color) {
 	uv_offset := shd.default_input_offsets[.UV]
 	color_offset := shd.default_input_offsets[.Color]
 	
+	mem.set(&s.vertex_buffer_cpu[base_offset], 0, shd.vertex_size)
+
 	if pos_offset != -1 {
 		(^Vec2)(&s.vertex_buffer_cpu[base_offset + pos_offset])^ = v
 	}

+ 1 - 0
window_win32.odin

@@ -167,4 +167,5 @@ WIN32_VK_MAP := [255]Keyboard_Key {
 	win32.VK_RIGHT = .Right,
 	win32.VK_UP = .Up,
 	win32.VK_DOWN = .Down,
+	win32.VK_RETURN = .Enter,
 }