Here's an attempt of capturing the controls of Star Fox. The SNES had no analogue stick, yet the controls of Star Fox felt awesome. We'll see what happens when obstacles and enemies are added.
Code:
' flight_test.n7
' --------------
' Move with arrow keys, shoot with space bar. Change y-axis inversion below if you need to.
include "s3d.n7"
constant RES = 480
' Set to 1 for non-inverted y-axis. I can only play inverted ...
ctrlYScale = -1
winAspect = min(screenw()/screenh(), 2)
set window "flight test", RES*winAspect, RES, false
set redraw off
while not keydown(KEY_ESCAPE, true)
' Change direction.
dYaw = 0
dPitch = 0
if keydown(KEY_LEFT) dYaw = dYaw - 45
if keydown(KEY_RIGHT) dYaw = dYaw + 45
if keydown(KEY_UP) dPitch = dPitch + 30*ctrlYScale
if keydown(KEY_DOWN) dPitch = dPitch - 30*ctrlYScale
ship.rot.yaw = 0.95*ship.rot.yaw + 0.05*dYaw
ship.rot.pitch = 0.95*ship.rot.pitch + 0.05*dPitch
ship.rot.roll = 0.95*ship.rot.roll + 0.05*dYaw*0.5
' Get ships direction as a vector.
S3D_ClearTransformation()
' A window aspect effect is applied in ClearTransformation, so we have to revert it to get
' proper coordinates from TransformVector. I have ... NO idea of why I did it like that. I'll
' fix that in the next n7 release.
S3D_Scale(winAspect, 1, 1)
S3D_RotateY(rad(ship.rot.yaw))
S3D_RotateX(rad(ship.rot.pitch))
S3D_RotateZ(rad(ship.rot.roll))
S3D_TransformVector(ship.dir, fwdVec)
VectorNormalize(ship.dir)
' Uhm, slow down when close to x and y limits.
dxMul = 1; dyMul =1
if ship.dir[0] < 0 dxMul = min(ship.pos[0] - xMin, 4)*0.25
elseif ship.dir[0] > 0 dxMul = min(xMax - ship.pos[0], 4)*0.25
if ship.dir[1] < 0 dyMul = min(ship.pos[1] - yMin, 4)*0.25
elseif ship.dir[1] > 0 dyMul = min(yMax - ship.pos[1], 4)*0.25
' Update bullets.
i = 0
while i < sizeof(bullets)
b = bullets[i]
VectorAdd(b.pos, b.mvec)
if b.pos[1] >= 0 or b.pos[2] > cam.pos[2] + 50 free key bullets, i
else i = i + 1
wend
(09-12-2025, 12:18 AM)johnno56 Wrote: That is SO cool!! Very smooth indeed.... Looking forward to shooting and blowing stuff up... Ha... I'll even dust of my joystick... Moo Ha Ha Ha...
Do you play these kind of games with inverted y-axis (press down to look up) or not? I'm just curious I believe it was Top Gun on NES that made me an inverted player for life. I have bought games that I've never been able to play because there's been no option to invert the controls.
I'm trying to give a starfleet effect as a background, but I'm curious, why the stars are not coming from the center of the screen. Would you please advise me ? Thank you.
Code:
' flight_test.n7
' --------------
' Move with arrow keys, shoot with space bar. Change y-axis inversion below if you need to.
include "s3d.n7"
constant RES = 480
' Set to 1 for non-inverted y-axis. I can only play inverted ...
ctrlYScale = -1
winAspect = min(screenw()/screenh(), 2)
set window "flight test", RES*winAspect, RES, false
set redraw off
'-----------------------------
'starfleet
visible stars = []
for i = 0 to 199 stars[i] = [x: rnd()*2-1, y:rnd()*2-1, z:0.1+rnd()*0.9]
'center of the screen
visible wp = screenw()/2
visible hp = screenh()/2
'------------------------------
' MAIN PROGRAM
while not keydown(KEY_ESCAPE, true)
' Change direction.
dYaw = 0
dPitch = 0
if keydown(KEY_LEFT) dYaw = dYaw - 45
if keydown(KEY_RIGHT) dYaw = dYaw + 45
if keydown(KEY_UP) dPitch = dPitch + 30*ctrlYScale
if keydown(KEY_DOWN) dPitch = dPitch - 30*ctrlYScale
ship.rot.yaw = 0.95*ship.rot.yaw + 0.05*dYaw
ship.rot.pitch = 0.95*ship.rot.pitch + 0.05*dPitch
ship.rot.roll = 0.95*ship.rot.roll + 0.05*dYaw*0.5
' Get ships direction as a vector.
S3D_ClearTransformation()
' A window aspect effect is applied in ClearTransformation, so we have to revert it to get
' proper coordinates from TransformVector. I have ... NO idea of why I did it like that. I'll
' fix that in the next n7 release.
S3D_Scale(winAspect, 1, 1)
S3D_RotateY(rad(ship.rot.yaw))
S3D_RotateX(rad(ship.rot.pitch))
S3D_RotateZ(rad(ship.rot.roll))
S3D_TransformVector(ship.dir, fwdVec)
VectorNormalize(ship.dir)
' Uhm, slow down when close to x and y limits.
dxMul = 1; dyMul =1
if ship.dir[0] < 0 dxMul = min(ship.pos[0] - xMin, 4)*0.25
elseif ship.dir[0] > 0 dxMul = min(xMax - ship.pos[0], 4)*0.25
if ship.dir[1] < 0 dyMul = min(ship.pos[1] - yMin, 4)*0.25
elseif ship.dir[1] > 0 dyMul = min(yMax - ship.pos[1], 4)*0.25
' Update bullets.
i = 0
while i < sizeof(bullets)
b = bullets[i]
VectorAdd(b.pos, b.mvec)
if b.pos[1] >= 0 or b.pos[2] > cam.pos[2] + 50 free key bullets, i
else i = i + 1
wend
'--------------------------------------
function starfleet()
for i = 0 to 199
stars[i].z = stars[i].z - 0.01
if stars[i].z < 0.1
stars[i].z = stars[i].z + 0.9
endif
'Coordinate (x,y) is moving from center
x = wp + stars[i].x*wp/stars[i].z
y = hp + stars[i].y*hp/stars[i].z
radius = 1/stars[i].z
set color 255,255,255 'white
draw ellipse x,y,radius,radius,1 '1=filled
next
endfunc
'-----------------------------------------
' Get ships direction as a vector.
S3D_ClearTransformation()
' A window aspect effect is applied in ClearTransformation, so we have to revert it to get
' proper coordinates from TransformVector. I have ... NO idea of why I did it like that. I'll
' fix that in the next n7 release.
S3D_Scale(winAspect, 1, 1)
S3D_RotateY(rad(ship.rot.yaw))
S3D_RotateX(rad(ship.rot.pitch))
S3D_RotateZ(rad(ship.rot.roll))
S3D_TransformVector(ship.dir, fwdVec)
VectorNormalize(ship.dir)
' Uhm, slow down when close to x and y limits.
dxMul = 1; dyMul =1
if ship.dir[0] < 0 dxMul = min(ship.pos[0] - xMin, 4)*0.25
elseif ship.dir[0] > 0 dxMul = min(xMax - ship.pos[0], 4)*0.25
if ship.dir[1] < 0 dyMul = min(ship.pos[1] - yMin, 4)*0.25
elseif ship.dir[1] > 0 dyMul = min(yMax - ship.pos[1], 4)*0.25
' Update bullets.
i = 0
while i < sizeof(bullets)
b = bullets[i]
VectorAdd(b.pos, b.mvec)
if b.pos[1] >= 0 or b.pos[2] > cam.pos[2] + renderDepth free key bullets, i
else i = i + 1
wend
' Obstacle
' --------
function Obstacle(mesh, x, y, z, w, h, d)
o = [
mesh: mesh,
pos: [x, y, z],
box: [x - w*0.5, y - h, z - d*0.5, x + w*0.5, y, z + d*0.5]]
return o
endfunc
You will notice a flicker in the graphics. It's a bug when rendering solid color 3d polygons. By mistake I'm casting the z values at the vertices to integers and then interpolate those values over the polygons. I'll have it fixed in the next version of n7. I want to fix some more things too that would, among all, allow me to "cast shadows" not only on the ground but also on the obstacles. On the other hand, Star Fox didn't have that ...
(09-12-2025, 12:18 AM)johnno56 Wrote: That is SO cool!! Very smooth indeed.... Looking forward to shooting and blowing stuff up... Ha... I'll even dust of my joystick... Moo Ha Ha Ha...
Do you play these kind of games with inverted y-axis (press down to look up) or not?
Ha... Never gave that a thought... I just accepted what the game produced... In most cases, point the "nose" down and the background went "up"... etc But that was a long time ago...Back then I used a modified analogue stick with one button... Now I use a stick with heaps of buttons, top hat, slider and multiple triggers... Now... Where are you hiding those aliens? Moo Ha Ha Ha...
(09-12-2025, 06:36 AM)aurel Wrote: shadow of the ship in space ?
hmmm
Shadow? Nice catch! Actually, unless the "ship" was producing its own light, the ship would be virtually invisible to the eye.... After all, as it is so far from a light source, there would be no highlighting for it to be seen... Star Wars and star Trek have got a lot to answer for... lol
The stuff I've fixed and added to n7 make simple shadow casting work fine:
I render the ship as seen from above on an image and project that image on the ground and the obstacles. Anything that helps with depth perception is important in a game like this.