Game field, camera, first assets
This commit is contained in:
		
							
								
								
									
										
											BIN
										
									
								
								assets/ball.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								assets/ball.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 141 B | 
							
								
								
									
										
											BIN
										
									
								
								assets/jet.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								assets/jet.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 268 B | 
							
								
								
									
										
											BIN
										
									
								
								assets/pad.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								assets/pad.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 653 B | 
							
								
								
									
										
											BIN
										
									
								
								assets_src/ball.aseprite
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								assets_src/ball.aseprite
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								assets_src/jet.aseprite
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								assets_src/jet.aseprite
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								assets_src/pad.aseprite
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								assets_src/pad.aseprite
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										18
									
								
								game.odin
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								game.odin
									
									
									
									
									
								
							| @ -1,8 +1,12 @@ | |||||||
| package main | package main | ||||||
|  |  | ||||||
| import rl "vendor:raylib" | import rl "vendor:raylib" | ||||||
|  | import "vendor:raylib/rlgl" | ||||||
| import "core:fmt" | import "core:fmt" | ||||||
|  |  | ||||||
|  | // Virtual game field dimensions | ||||||
|  | GameField := Vec2{800, 600} | ||||||
|  |  | ||||||
|  |  | ||||||
| Pad :: struct { | Pad :: struct { | ||||||
| 	position: Vec2,  | 	position: Vec2,  | ||||||
| @ -29,6 +33,7 @@ Game :: struct { | |||||||
| 	pad: Pad, | 	pad: Pad, | ||||||
| 	balls: [dynamic]Ball, | 	balls: [dynamic]Ball, | ||||||
| 	bricks: [dynamic]Brick, | 	bricks: [dynamic]Brick, | ||||||
|  | 	camera: rl.Camera2D | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| @ -38,8 +43,12 @@ game_init :: proc() -> ^GameState { | |||||||
| 	state.draw = game_draw | 	state.draw = game_draw | ||||||
| 	state.update = game_update | 	state.update = game_update | ||||||
| 	state.lives = 3 | 	state.lives = 3 | ||||||
|  | 	state.camera = rl.Camera2D{ | ||||||
|  | 		zoom = 1, | ||||||
|  | 		target = GameField / 2, | ||||||
|  | 	} | ||||||
| 	state.pad = Pad{ | 	state.pad = Pad{ | ||||||
| 		position = {f32(WINDOW_WIDTH / 2), f32(WINDOW_HEIGHT - 40)}, | 		position = Vec2{GameField.x / 2, GameField.y - 40}, | ||||||
| 		size = {80, 10}, | 		size = {80, 10}, | ||||||
| 	} | 	} | ||||||
| 	return state | 	return state | ||||||
| @ -58,6 +67,8 @@ game_update :: proc(state: ^GameState, delta: f32) { | |||||||
| 		pad.position.x += 100 * delta | 		pad.position.x += 100 * delta | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	game.camera.offset = WINDOWF / 2 | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| game_draw :: proc(state: ^GameState) { | game_draw :: proc(state: ^GameState) { | ||||||
| @ -65,7 +76,12 @@ game_draw :: proc(state: ^GameState) { | |||||||
|  |  | ||||||
| 	using game | 	using game | ||||||
|  |  | ||||||
|  | 	rl.BeginMode2D(camera) | ||||||
|  |  | ||||||
| 	rl.ClearBackground(rl.RAYWHITE) | 	rl.ClearBackground(rl.RAYWHITE) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | 	rl.DrawRectangleV({0, 0}, GameField, rl.RED) | ||||||
| 	rl.DrawRectangleV(pad.position, pad.size, rl.GREEN) | 	rl.DrawRectangleV(pad.position, pad.size, rl.GREEN) | ||||||
|  | 	rl.EndMode2D() | ||||||
| } | } | ||||||
|  | |||||||
							
								
								
									
										20
									
								
								main.odin
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								main.odin
									
									
									
									
									
								
							| @ -2,22 +2,25 @@ package main | |||||||
|  |  | ||||||
| import rl "vendor:raylib" | import rl "vendor:raylib" | ||||||
| import "core:slice" | import "core:slice" | ||||||
|  | import "core:fmt" | ||||||
|  |  | ||||||
| Vec2 :: [2]f32 | Vec2 :: [2]f32 | ||||||
| Vec2i :: [2]i32 | Vec2i :: [2]i32 | ||||||
|  |  | ||||||
| WINDOW_WIDTH : i32 = 800 | WINDOW : Vec2i | ||||||
| WINDOW_HEIGHT : i32 = 480 | WINDOWF : Vec2 | ||||||
|  |  | ||||||
|  |  | ||||||
| main :: proc() { | main :: proc() { | ||||||
| 	rl.SetConfigFlags(rl.ConfigFlags{.BORDERLESS_WINDOWED_MODE, .VSYNC_HINT, .WINDOW_RESIZABLE}) | 	rl.SetConfigFlags(rl.ConfigFlags{.FULLSCREEN_MODE, .VSYNC_HINT, .WINDOW_MAXIMIZED,  .WINDOW_UNDECORATED}) | ||||||
| 	monitor := rl.GetCurrentMonitor() | 	monitor := rl.GetCurrentMonitor() | ||||||
| 	WINDOW_WIDTH = rl.GetMonitorWidth(monitor) | 	rl.InitWindow(0, 0, "SinePong") | ||||||
| 	WINDOW_HEIGHT = rl.GetMonitorHeight(monitor) |  | ||||||
| 	rl.InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "SinePong") |  | ||||||
| 	rl.SetTargetFPS(9999) | 	rl.SetTargetFPS(9999) | ||||||
|  |  | ||||||
|  | 	WINDOW.x = rl.GetScreenWidth() | ||||||
|  | 	WINDOW.y = rl.GetScreenHeight() | ||||||
|  | 	WINDOWF = Vec2{f32(WINDOW.x), f32(WINDOW.y)} | ||||||
|  |  | ||||||
| 	stack_init() | 	stack_init() | ||||||
|  |  | ||||||
| 	defer { | 	defer { | ||||||
| @ -31,8 +34,9 @@ main :: proc() { | |||||||
|  |  | ||||||
| 	for (!rl.WindowShouldClose()) { | 	for (!rl.WindowShouldClose()) { | ||||||
| 		if rl.IsWindowResized() { | 		if rl.IsWindowResized() { | ||||||
| 			WINDOW_WIDTH = rl.GetScreenWidth() | 			WINDOW.x = rl.GetScreenWidth() | ||||||
| 			WINDOW_HEIGHT = rl.GetScreenHeight() | 			WINDOW.y = rl.GetScreenHeight() | ||||||
|  | 			WINDOWF = Vec2{f32(WINDOW.x), f32(WINDOW.y)} | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		current_state := state_stack[len(state_stack)-1] | 		current_state := state_stack[len(state_stack)-1] | ||||||
|  | |||||||
							
								
								
									
										
											BIN
										
									
								
								sineys-arkanoid
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								sineys-arkanoid
									
									
									
									
									
										Executable file
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -23,6 +23,7 @@ STACK_SIZE :: 16 | |||||||
| state_buf : [STACK_SIZE]^GameState | state_buf : [STACK_SIZE]^GameState | ||||||
| state_stack : [dynamic]^GameState | state_stack : [dynamic]^GameState | ||||||
|  |  | ||||||
|  |  | ||||||
| stack_init :: proc() { | stack_init :: proc() { | ||||||
| 	state_stack = slice.into_dynamic(state_buf[:]) | 	state_stack = slice.into_dynamic(state_buf[:]) | ||||||
| } | } | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user