Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pixel Collision
#3
(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)
Reply


Messages In This Thread
Pixel Collision - by johnno56 - 04-09-2024, 09:08 AM
RE: Pixel Collision - by johnno56 - 04-09-2024, 11:25 AM
RE: Pixel Collision - by 1micha.elok - 04-09-2024, 03:37 PM
RE: Pixel Collision - by johnno56 - 04-09-2024, 06:21 PM
RE: Pixel Collision - by 1micha.elok - 04-10-2024, 02:04 AM
RE: Pixel Collision - by johnno56 - 04-10-2024, 02:26 AM
RE: Pixel Collision - by 1micha.elok - 04-10-2024, 03:22 AM
RE: Pixel Collision - by kevin - 04-10-2024, 06:52 AM
RE: Pixel Collision - by 1micha.elok - 04-10-2024, 08:05 AM
RE: Pixel Collision - by johnno56 - 04-11-2024, 01:19 AM
RE: Pixel Collision - by kevin - 04-11-2024, 06:14 AM
RE: Pixel Collision - by johnno56 - 04-11-2024, 09:30 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)