04-09-2024, 03:37 PM
(04-09-2024, 11:25 AM)johnno56 Wrote: I figured that I would test the pixel detection using RCBasic... Apart from running much slower, not only did I convert the program correctly, I also recreated the same result. Logic would seem to dictate that it would be highly unlikely that two different programing languages would experience the same error, N7 using pixel() and RC using getPixel()... I am left with no other explanation except for 'programmer error'...
So much for that idea... moving on... lol
PIXEL COLLISION
click on each image to zoom in
Please try this code in N7
Code:
'----------------
' INITIALIZATION
'----------------
set window "Pixel Collision", 640, 480
set redraw off
'color definition
white = [255,255,255]
black = [0,0,0]
green = [0,255,0]
'Box
box = []
box.w = 32
box.h = 48
box.x = (width(primary)-box.w)/2
box.y = 0
box.speed = 0
box.drop = false
'Ground
ground = []
ground.x = 0
ground.y = height(primary)/2
ground.w = 640
ground.h = 60
'Get color by Pixel()
getcolor = []
'-----------
' MAIN LOOP
'-----------
do
'clear screen
set color black;cls; set color white
'box movement
if keydown(KEY_SPACE, true) then box.drop = true
if box.drop = true then
box.speed = box.speed + 0.03
else
box.speed = 0
endif
box.y = box.y + box.speed
'draw green ground and white box
set color green; draw rect ground.x,ground.y,ground.w,ground.h,1
set color white; draw rect box.x,box.y,box.w,box.h,1
'collision detection by Pixel()
getcolor = pixel(box.x,box.y+box.h)
if getcolor[0]=green[0] and getcolor[1]=green[1] and getcolor[2]=green[2] then
box.drop = false
endif
'info
set caret width(primary)/2,height(primary)-50;center "Press SPACE BAR to drop the white box"
redraw
fwait 30
until keydown(KEY_ESCAPE, true)