raylib/ports/core/core_input_keys
Licence This example has its own licence, rather than Odin's: raylib/ports/LICENSE
These are ported Raylib examples, and as such, they are subject to Raylib's license.
Copyright (c) 2013-2024 Ramon Santamaria (@raysan5)
The rest of the licence
This software is provided "as-is", without any express or implied warranty. In no event
will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you
wrote the original software. If you use this software in a product, an acknowledgment
in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented
as being the original software.
3. This notice may not be removed or altered from any source distribution.
Code
core_input_keys.odin ¶76 linesSource
1/*******************************************************************************************
2*
3* raylib [core] example - input keys
4*
5* Example complexity rating: [★☆☆☆] 1/4
6*
7* Example originally created with raylib 1.0, last time updated with raylib 1.0
8*
9* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
10* BSD-like license that allows static linking with closed source software
11*
12* Copyright (c) 2014-2025 Ramon Santamaria (@raysan5)
13*
14********************************************************************************************/
15
16package raylib_examples
17
18import rl "vendor:raylib"
19
20//------------------------------------------------------------------------------------
21// Program main entry point
22//------------------------------------------------------------------------------------
23main :: proc() {
24 // Initialization
25 //--------------------------------------------------------------------------------------
26 SCREEN_WIDTH :: 800
27 SCREEN_HEIGHT :: 450
28
29 rl.InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "raylib [core] example - input keys")
30
31 ball_position := rl.Vector2 {SCREEN_WIDTH/2, SCREEN_HEIGHT/2}
32
33 rl.SetTargetFPS(60) // Set our game to run at 60 frames-per-second
34 //--------------------------------------------------------------------------------------
35
36 // Main game loop
37 for !rl.WindowShouldClose() { // Detect window close button or ESC key
38 // Update
39 //----------------------------------------------------------------------------------
40 if rl.IsKeyDown(.RIGHT) {
41 ball_position.x += 2
42 }
43
44 if rl.IsKeyDown(.LEFT) {
45 ball_position.x -= 2
46 }
47
48 if rl.IsKeyDown(.UP) {
49 ball_position.y -= 2
50 }
51
52 if rl.IsKeyDown(.DOWN) {
53 ball_position.y += 2
54 }
55
56 //----------------------------------------------------------------------------------
57
58 // Draw
59 //----------------------------------------------------------------------------------
60 rl.BeginDrawing()
61
62 rl.ClearBackground(rl.RAYWHITE)
63
64 rl.DrawText("move the ball with arrow keys", 10, 10, 20, rl.DARKGRAY)
65
66 rl.DrawCircleV(ball_position, 50, rl.MAROON)
67
68 rl.EndDrawing()
69 //----------------------------------------------------------------------------------
70 }
71
72 // De-Initialization
73 //--------------------------------------------------------------------------------------
74 rl.CloseWindow() // Close window and OpenGL context
75 //--------------------------------------------------------------------------------------
76}
Declarations Used 14
- vendor:raylib BeginDrawing · ClearBackground · CloseWindow · DARKGRAY · DrawCircleV · DrawText · EndDrawing · InitWindow · IsKeyDown · MAROON · RAYWHITE · SetTargetFPS · Vector2 · WindowShouldClose