-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtextures_rectangle.bas
More file actions
80 lines (66 loc) · 2.62 KB
/
textures_rectangle.bas
File metadata and controls
80 lines (66 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
REM ----------------------------------------------------------------------------------------
REM
REM raylib [textures] example - Texture loading and drawing a part defined by a rectangle
REM
REM This example has been created using raylib 1.7 (www.raylib.com)
REM raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
REM
REM Copyright (c) 2017 Ramon Santamaria (@raysan5)
REM
REM ----------------------------------------------------------------------------------------
import raylib as rl
import raylibc as c
local MAX_FRAME_SPEED = 14
local MIN_FRAME_SPEED = 1
local screenWidth = 800
local screenHeight = 450
local position = [350.0, 280.0]
local frameRec = {x:0, y:0, width:0, height:0}
local currentFrame = 0
local framesCounter = 0
local framesSpeed = 8
rl.InitWindow(screenWidth, screenHeight, "raylib [texture] example - texture rectangle")
rl.SetTargetFPS(60)
REM NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
local scarfy = rl.LoadTexture(CWD + "raylib/examples/textures/resources/scarfy.png")
frameRec.width = scarfy.width / 6
frameRec.height = scarfy.height
REM Main game loop
while (!rl.WindowShouldClose())
framesCounter = framesCounter + 1
if (framesCounter >= (60/framesSpeed)) then
framesCounter = 0
currentFrame = currentFrame + 1
if (currentFrame > 5) then currentFrame = 0
frameRec.x = currentFrame * scarfy.width / 6
endif
if (rl.IsKeyPressed(c.KEY_RIGHT)) then
framesSpeed = framesSpeed + 1
elseif (rl.IsKeyPressed(c.KEY_LEFT)) then
framesSpeed = framesSpeed - 1
endif
if (framesSpeed > MAX_FRAME_SPEED) then
framesSpeed = MAX_FRAME_SPEED
elseif (framesSpeed < MIN_FRAME_SPEED) then
framesSpeed = MIN_FRAME_SPEED
endif
rl.BeginDrawing()
rl.ClearBackground(c.RAYWHITE)
rl.DrawTexture(scarfy, 15, 40, c.WHITE)
rl.DrawRectangleLines(15, 40, scarfy.width, scarfy.height, c.LIME)
rl.DrawRectangleLines(15 + frameRec.x, 40 + frameRec.y, frameRec.width, frameRec.height, c.RED)
rl.DrawText("FRAME SPEED: ", 165, 210, 10, c.DARKGRAY)
rl.DrawText(format("## FPS", framesSpeed), 575, 210, 10, c.DARKGRAY)
rl.DrawText("PRESS RIGHT/LEFT KEYS to CHANGE SPEED!", 290, 240, 10, c.DARKGRAY)
for i = 1 to MAX_FRAME_SPEED
if (i <= framesSpeed) then
rl.DrawRectangle(250 + 21*i, 205, 20, 20, c.RED)
endif
rl.DrawRectangleLines(250 + 21*i, 205, 20, 20, c.MAROON)
next i
rl.DrawTextureRec(scarfy, frameRec, position, c.WHITE)
rl.DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth - 200, screenHeight - 20, 10, c.GRAY)
rl.EndDrawing()
wend
rl.UnloadTexture(scarfy)
rl.CloseWindow()