(05-28-2024, 05:02 AM)1micha.elok Wrote:(05-27-2024, 06:30 PM)Marcus Wrote: I had a really busy weekend. Jazz concert (my son) on Saturday and gymnastics competion (daughter) on Sunday. ....
You are so lucky to have an awesome family time. Great !!!
By the way, you may reply my question when you are free, it's not urgent
click the image to zoom-in
I'm trying to make a kind of first-person-shooter game, but I believe I do it in a wrong way .... lol
a. Could you please advice me the right-way, where should I put the code of draw image weapon ?
b. And how to put the weapon at the middle of the bottom screen ?
I can not put it as draw image weapon, width(primary)/2, height(primary) as it will draw out of screen.
Code:'---------------
' INITILIZATION
'---------------
include "myassets/enginea.n7"
set window "stargate",320,240,false,2
set redraw off
visible weapon = loadimage("myassets/shooter.png")
EA_SetView(primary, rad(65), 0.1,6)
EA_SetFog(EA_NORMAL, 255,255,255)
flags = EA_LoadMap("myassets/map.json")
player = unset
foreach f in flags
if f.flag = "player"
player = EA_FpsPlayer()
player.SetPos(f.x,f.floorY, f.z)
endif
next
'------
' MAIN
'------
EA_AddObject(player)
EA_SetCamera(player)
player.SetMouseSens(0.3)
EA_SetUpdateAction(Update)
EA_Run()
'-----------
' FUNCTIONS
'-----------
function Update(dt)
draw image weapon, 100,130
redraw
fwait 30
if keydown(KEY_ESCAPE,true) then
EA_Stop()
endif
endfunc
The next step in the tutorial will show you how to do that, as you can see in the video above. But ... I can tell you right now.
Use EA_SetDrawAction(func) to set a callback function that will be called every frame when the scene has been rendered:
Code:
EA_SetDrawAction(Draw)
...
function Draw()
set color 255, 255, 255
draw image gunImage, (width(primary) - width(gunImage))/2, height(primary) - height(gunImage)
endfunc