Facebook
From archkubi, 1 Year ago, written in C.
This paste is a reply to Untitled from archkubi - go back
Embed
Viewing differences between Untitled and Re: Untitled
import nimraylib_now
import std/random

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

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

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

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

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

275
 
## astroid
type
  AstroObject = object
    texture: Texture2D
Image
    x, y: int
    speed: float
    active: bool

bool


var numAstros = 5
var astros: seq[AstroObject]

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


setTargetFPS(60) 
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)

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
  \n 
  ## gravity
  if KeyboardKey.SPACE.isKeyDown and not isJumping:
    isJumping = true
    yPos -= jumForce

  # 
jumForce
 
  ## 
astro
  if for astro in astros:
    astro.y += float(astrp.speed)
astro.speed
    if astro.y > screenHeight:
      astro.y = -random(1.-random(1..1000)
      astro.x = random(1..906)
      astro.speed = random(1..4)
    \n   
  ## 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)

WHITE)
 
  ## player
  drawTexture(player, xPos, yPos, White)

White)
 
  ## draw astros
  for astro in astros:
    if astro.active:
      drawTexture(astro.texture, int(astro.x), int(astro.y), WHITE)



WHITE)
 
 
 
  endDrawing()
closeWindow()
closeWindow()