import nimraylib_now import std/random 

## 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 image")

## background

var image: Image = 
loadImage("/home/archkubi/Github/gnuchange/nimRaylib/src/img/bg.png") var 
texture: Texture2D = loadTextureFromImage(image)

## 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.png")

var player: Texture2D = loadTextureFromImage(playerFront) var xPos = 
screenWidth div 2 - 90 var yPos = screenHeight div 2 - 64 + 180

## gravity

var gravity = 5 var jumForce = 120 var isJumping = false var groundHeight = 
screenHeight / 2 - 275

## astroid

type
    

AstroObject = object
    texture: Texture2D x, y: int speed: float active: bool

var numAstros = 5 var astros: seq[AstroObject]

for i in 0 ..< numAstros:
    var astro_texture = loadImage("img/astro.png") var astro_x = 
random.rand(1..906) var astro_y = random.rand(1..1000) var astroSpeed = 
random.rand(1..4) var astroObject = AstroObject(astro_texture, astro_x, 
astro_y, astroSpeed) astros.add(astroObject)

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 = loadTextureFromImage(playerFront)

## 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 -= jumForce

# astro

if astro in astros:
    astro.y += float(astrp.speed)

if astro.y > screenHeight:
    astro.y = -random(1.1000) 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, 
WHITE)

## player

drawTexture(player, xPos, yPos, White)

## draw astros

for astro in astros:
    

if astro.active:
    drawTexture(astro.texture, int(astro.x), int(astro.y), WHITE)

endDrawing()

closeWindow() 

Reply via email to