Facebook
From archkubi, 1 Year ago, written in C.
Embed
Download Paste or View Raw
Hits: 387
  1. import nimraylib_now
  2. import std/random
  3.  
  4. ## window and window size
  5. var screenWidth = 1024
  6. var screenHeight = 600
  7. ## SetTraceLogLevel(LOG_ERROR) this is not in
  8. initWindow(screenWidth, screenHeight,
  9.            "raylib [textures] example - texture to image")
  10.  
  11. ## background
  12. var image: Image = loadImage("/home/archkubi/Github/gnuchange/nimRaylib/src/img/bg.png")
  13. var texture: Texture2D = loadTextureFromImage(image)
  14.  
  15. ## player
  16. var playerFront: Image = loadImage("/home/archkubi/Github/gnuchange/nimRaylib/src/img/front.png")
  17. var playerLeft: Image = loadImage("/home/archkubi/Github/gnuchange/nimRaylib/src/img/left.png")
  18. var playerRight: Image = loadImage("/home/archkubi/Github/gnuchange/nimRaylib/src/img/right.png")
  19.  
  20. var player: Texture2D = loadTextureFromImage(playerFront)
  21. var xPos = screenWidth div 2 - 90
  22. var yPos = screenHeight div 2 - 64 + 180
  23.  
  24. ## gravity
  25. var gravity = 5
  26. var jumForce = 120
  27. var isJumping = false
  28. var groundHeight = screenHeight / 2 - 275
  29.  
  30. ## astroid
  31. type
  32.   AstroObject = object
  33.     texture: Texture2D
  34.     x, y: int
  35.     speed: float
  36.     active: bool
  37.  
  38. var numAstros = 5
  39. var astros: seq[AstroObject]
  40.  
  41. for i in 0 ..< numAstros:
  42.   var astro_texture = loadImage("img/astro.png")
  43.   var astro_x = random.rand(1..906)
  44.   var astro_y = random.rand(1..1000)
  45.   var astroSpeed = random.rand(1..4)
  46.   var astroObject = AstroObject(astro_texture, astro_x, astro_y, astroSpeed)
  47.   astros.add(astroObject)
  48.  
  49.  
  50. setTargetFPS(60)
  51. while not windowShouldClose():
  52.   if KeyboardKey.A.isKeyDown and xPos > 0:
  53.     xPos -= 5 * 1
  54.     player = loadTextureFromImage(playerLeft)
  55.   elif KeyboardKey.D.isKeyDown and xPos < 905:
  56.     xPos += 5 * 1
  57.     player = loadTextureFromImage(playerRight)
  58.   else:
  59.     player = loadTextureFromImage(playerFront)
  60.  
  61.   ## jump
  62.   var characterBaseY = yPos + player.height
  63.   var floor = int(screenHeight) - int(groundHeight)
  64.   if characterBaseY >= floor:
  65.     isJumping = false
  66.     yPos = floor - player.height
  67.   else:
  68.     yPos += gravity
  69.  
  70.   ## gravity
  71.   if KeyboardKey.SPACE.isKeyDown and not isJumping:
  72.     isJumping = true
  73.     yPos -= jumForce
  74.  
  75.   # astro
  76.   if astro in astros:
  77.     astro.y += float(astrp.speed)
  78.     if astro.y > screenHeight:
  79.       astro.y = -random(1.1000)
  80.       astro.x = random(1..906)
  81.       astro.speed = random(1..4)
  82.    
  83.   ## normal
  84.   beginDrawing()
  85.   drawTexture(texture, screenWidth div 2 - texture.width div 2, screenHeight div 2 - texture.height div 2, White)
  86.   drawRectangle(0, 570, screenWidth, 30,  WHITE)
  87.   drawFPS(10, 10)
  88.   drawText("This is Nim", 200, 20, 50, WHITE)
  89.  
  90.   ## player
  91.   drawTexture(player, xPos, yPos, White)
  92.  
  93.   ## draw astros
  94.   for astro in astros:
  95.     if astro.active:
  96.       drawTexture(astro.texture, int(astro.x), int(astro.y), WHITE)
  97.  
  98.  
  99.  
  100.   endDrawing()
  101. closeWindow()
  102.  

Replies to Untitled rss

Title Name Language When
Re: Untitled archkubi c 1 Year ago.