Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pixel Collision
#5
(04-09-2024, 06:21 PM)johnno56 Wrote: So... in a nutshell... because the colours are defined as a table, each element of the table, must detect the collision colour in order to function correctly?

Oh... Just for giggles... Instead of using filled rectangles, just use unfilled rectangles, then let me know if you get the same results as I?

Pixel Collision v2 - Unfiled rectangle

           
click each image to zoom in

Code:
'----------------
' INITIALIZATION
'----------------
set window "Pixel Collision v2", 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    = []
startscreen = true

'-----------
' MAIN LOOP
'-----------
do
    'clear screen
    set color black;cls; set color white
    if startscreen then
        message = "Press SPACE BAR to drop the box"
        startscreen = false
    endif
       
    'box movement   
    if keydown(KEY_SPACE, true) then box.drop = true
    if box.drop = true  then
        box.speed = box.speed + 0.03
        message = "the box is falling..."
    else
        box.speed = 0
    endif
    box.y = box.y + box.speed

    'info
    set caret width(primary)/2,height(primary)-50;center message   
         
    '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
   
    '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
        message = "the box is on the ground"
    endif 
                                   
    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: 3 Guest(s)