import
## window and window size
var screenWidth = 1024
var screenHeight = 600
## SetTraceLogLevel(LOG_ERROR) this is not in
initWindow(screenWidth, screenHeight,
"raylib [textures] example - texture to
## background
var image: Image = loadImage("/home/archkubi/Github/gnuchange/nimRaylib/src/img/bg.png")
var texture: Texture2D =
## player
var playerFront: Image = loadImage("/home/archkubi/Github/gnuchange/nimRaylib/src/img/front.png")
var playerLeft: Image = loadImage("/home/archkubi/Github/gnuchange/nimRaylib/src/img/left.png")
var playerRight: Image = loadImage("/home/archkubi/Github/gnuchange/nimRaylib/src/img/right.
var player: Texture2D = loadTextureFromImage(playerFront)
var xPos = screenWidth div 2 - 90
var yPos = screenHeight div 2 - 64 +
## gravity
var gravity = 5
var jumForce = 120
var isJumping = false
var groundHeight = screenHeight / 2 -
## astroid
type
AstroObject = object
texture:
x, y: int
speed: float
active:
var numAstros = 5
var astros: seq[AstroObject]
for i in 0 ..< numAstros:
var astro_texture =
var astro_x = random.
var astro_y = random.
var astroSpeed = random.
var astroObject = AstroObject(astro_texture, astro_x, astro_y, astroSpeed)
astros.
setTargetFPS(60)
setTargetFPS(60)
while not windowShouldClose():
if KeyboardKey.A.isKeyDown and xPos > 0:
xPos -= 5 * 1
player = loadTextureFromImage(playerLeft)
elif KeyboardKey.D.isKeyDown and xPos < 905:
xPos += 5 * 1
player = loadTextureFromImage(playerRight)
else:
player =
## jump
var characterBaseY = yPos + player.height
var floor = int(screenHeight) - int(groundHeight)
if characterBaseY >= floor:
isJumping = false
yPos = floor - player.height
else:
yPos += gravity
## gravity
if KeyboardKey.SPACE.isKeyDown and not isJumping:
isJumping = true
yPos -=
#
## astro
astro.y +=
if astro.y > screenHeight:
astro.y =
astro.x = random(1..906)
astro.speed = random(1..4)
## normal
beginDrawing()
drawTexture(texture, screenWidth div 2 - texture.width div 2, screenHeight div 2 - texture.height div 2, White)
drawRectangle(0, 570, screenWidth, 30, WHITE)
drawFPS(10, 10)
drawText("This is Nim", 200, 20, 50,
## player
drawTexture(player, xPos, yPos,
## draw astros
for astro in astros:
if astro.active:
drawTexture(astro.texture, int(astro.x), int(astro.y),
endDrawing()