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()
Replies to Untitled 
Title |
Name |
Language |
UNIX |
When |
Re: Untitled |
archkubi |
c |
1698486079 |
1 Year ago. |
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}