Do not ask about version one. Let's not go there... lol
Anyway... Here is version 2 using the new pixeli() command for collision detection.
You know how it works. Left and right arrow keys to move left and right. Up arrow to apply vertical thrust. Land on the green Pad. (Not too fast) Watch your fuel... there is no more until the very last level. Spoiler alert: Hold your breath for level nine.
ToDo:
Collision detection still flaky for level 10.
No background noise or music track.... open to suggestions.
Add "your" recommendations... (assuming "I" can do it. lol)
The mummy is everywhere when I am facing North, South, West etc ... lol .....
Is there a way to put the mummy somewhere in certain coordinate (x,y,z) ?
Code:
'==================================================
' THE MAZE II
' Part 1. Sand Desert
' Part 2. to be
' Part 3. to be
'
' Control :
' SPACE = move forward
' Mouse = see around
'
' Reference :
' - s3d.n7 library, ex6_heightmap.n7 by Marcus
'
' Sand texture https://images.app.goo.gl/QwsHZq7hZVdyNXB76
' Mummy1 https://images.app.goo.gl/uiosCKdMHraZPfoC7
' Title https://images.app.goo.gl/AGLmRC8g9vQDg21Q6
'==================================================
'----------------
' INITIALIZATION
'----------------
include "data_maze2/heightmap_library.n7"
include "s3d.n7"; S3D_SetView(primary, rad(90), 0.1, 5)
set window "Maze 2 - Part 1.Sand Desert",400,200,false,3
set mouse off
set redraw off
'color definition
gray = [128,128,128]
black = [0,0,0]
white = [255,255,255]
red = [255,0,0]
green = [0,255,0]
darkgreen = [0,128,0,120]
' Just simple draw image
set color white
draw image mummy[1].img, 20,20
'------------
' navigation
'------------
set color black
set caret 0,0; wln "Angle "+camYaw 'camYaw = 0 south, 90 east, 180 north, 270 west
wln "Position "+pos.x+","+pos.y+","+pos.z
set color darkgreen ; draw ellipse map.cx,map.cz,map.r,map.r,true
set color green
draw ellipse map.cx,map.cz,map.r,map.r
draw line map.cx,map.cz,map.cx+map.r*cos(rad(map.a)),map.cz+map.r*sin(rad(map.a))
set color red ; draw ellipse (map.x+int(pos.x)),(map.z+int(pos.z)),2,2,true
set color white ; draw ellipse (map.x+int(pos.x)),(map.z+int(pos.z)),2,2
set caret map.cx-18, map.z-13; wln "North"
set caret map.cx-18, map.z+map.h; wln "South"
set caret map.x-35, map.cz-5; wln "West"
set caret map.x+map.w+5, map.cz-5; wln "East"
I wrote a quick test for how collisions between moving objects (player and enemies) and the static walls should work in that 3d thing I'm working on. In the game/engine I will just check for collisions with walls close to the moving objects (a uniform grid will contain information about which walls passes through each cell). But maybe someone may still find this test useful for their own purposes:
Code:
set window "Collision", 640, 480
set redraw off
lines = []
randomize 11
for i = 1 to 8
ln = [rnd(640), rnd(480), rnd(640), rnd(480)]
dx = ln[2] - ln[0]; dy = ln[3] - ln[1]
ln[6] = sqr(dx*dx + dy*dy)
ln[4] = dx/ln[6]
ln[5] = dy/ln[6]
lines[sizeof(lines)] = ln
next
obj = Object(320, 240, 16)
while not keydown(KEY_ESCAPE, true)
'obj.x = mousex(); obj.y = mousey()
if keydown(KEY_LEFT) obj.x = obj.x - 4
if keydown(KEY_RIGHT) obj.x = obj.x + 4
if keydown(KEY_UP) obj.y = obj.y - 4
if keydown(KEY_DOWN) obj.y = obj.y + 4
PushOut(obj, lines)
set color 0, 0, 0
cls
set color 255, 255, 255
DrawLines(lines)
obj.Draw()
set caret width(primary)/2, 0
center "Use the arrow keys to move the circle around"
redraw
fwait 60
wend
function DrawLines(lines)
foreach ln in lines draw line ln[0], ln[1], ln[2], ln[3]
endfunc
function Object(x, y, r)
return [x: x, y: y, r: r, rsqr: r*r,
Draw: function(); draw ellipse .x, .y, .r, .r, false; endfunc]
endfunc
function PushOut(obj, lines)
' Let all lines push the object around a maximum of 10 times. This is not a recommended
' approach, just for testing.
tests = 10
for i = 1 to tests
col = false
foreach ln in lines
dp = max(0, min(ln[6], (obj.x - ln[0])*ln[4] + (obj.y - ln[1])*ln[5]))
px = ln[0] + dp*ln[4]; py = ln[1] + dp*ln[5]
dx = obj.x - px; dy = obj.y - py
d = dx*dx + dy*dy
if d < obj.rsqr
k = 1/sqr(d)
obj.x = px + dx*k*obj.r
obj.y = py + dy*k*obj.r
col = true
endif
next
if not col break
next
endfunc
This is pretty much how I did it in the GLOOM library for n6 too, if my memory is correct (source code since long gone).
This is a project I started back on 19th October 2016 using SDLBasic...
Over the years it has been ported to QB64 and RCBasic (Jan 2022)
The game is simple. Left Mouse Button or Space to flap. Fly through the "gaps" in the pipes. Each pipe passed is one point. Warning: The game will speed up gradually (usually after every 5 pipes) to a maximum speed of "8"....
You can now use 'pixeli(x, y)' or 'pixeli(image_id, x, y)' to get the color of an image's pixel as a single number. You can also use 'set colori' to set the current drawing color using such a number.
If you need to convert RGB or RGBA values to a single number color, you can use functions like these:
Code:
function ToRGB(r, g, b)
return 255*16777216 + r*65536 + g*256 + b
endfunc
function ToRGBA(r, g, b, a)
return a*16777216 + r*65536 + g*256 + b
endfunc
And to get the RGBA components of a single number color:
Code:
function Alpha(c)
return int(c/16777216)
endfunc
function Red(c)
return int((c/65536))%256
endfunc
function Green(c)
return int((c/256))%256
endfunc
function Blue(c)
return c%256
endfunc
2024-04-14
Added the 'pixeli' function and 'set colori' command to get and set colors as single numbers
A question, if I have two objects and one is the player who can move with the keys and the other is the enemy who is stationary in one place on the screen.
The question would be how can I make it so that when the player is close to the enemy he starts chasing the player and if the player moves away the enemy stops chasing him and returns to the starting position.