Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rotated and scaled image drawing
#8
And here we go with the texture mapping using 'draw poly image' Smile

Code:
#win32

set window "nah ...", 640, 480, false
set redraw off

' create two road textures.
roadImg = []
roadImg[0] = createimage(160, 16)
set image roadImg[0]
for y = 0 to 15  for x = 0 to 159
    if rnd(3) = 0  set color 128, 128, 128
    else  set color 112, 112, 112
    set pixel x, y
next
set color 255, 255, 255
draw rect 0, 0, 8, 16, true
draw rect 152, 0, 8, 16, true
set image primary
roadImg[1] = createimage(160, 16)
set image roadImg[1]
for y = 0 to 15  for x = 0 to 159
    if rnd(3) = 0  set color 96, 96, 96
    else  set color 80, 80, 80
    set pixel x, y
next
set color 255, 255, 255
draw rect 76, 0, 8, 16, true
set image primary



road = []
for z = 0 to 200  road[z] = sin(z*0.05)*6

playerz = 0.0
playerx = 0
p = dim(16)
p[2] = 0; p[3] = 0
p[6] = 160; p[7] = 0
p[10] = 160; p[11] = 16
p[14] = 0; p[15] = 16
while not keydown(KEY_ESCAPE, true)
    playerz = playerz + 0.075
    if keydown(KEY_LEFT)  playerx = playerx - 0.1
    if keydown(KEY_RIGHT) playerx = playerx + 0.1

    set color 64, 64, 128
    cls
    set color 200, 128, 64
    draw rect 0, 125*2, 640, 240, true
    
    set color 255, 255, 255
    for i = int(playerz) + 20 to int(playerz)
        if i < sizeof(road) - 2
            z = i + 1 - playerz + 1.1
            x0l = 320 + 400*(road[i + 1] - 1 - playerx)/z
            x0r = 320 + 400*(road[i + 1] + 1 - playerx)/z
            y0 = 240 + 260/z
            z = i - playerz + 1.1
            x1l = 320 + 400*(road[i] - 1 - playerx)/z
            x1r = 320 + 400*(road[i] + 1 - playerx)/z
            y1 = 240 + 260/z
'            if i%2 = 0  set color 128, 128, 128
'            else  set color 96, 96, 96
            p[0] = x0l; p[1] = y0;
            p[4] = x0r; p[5] = y0
            p[8] = x1r; p[9] = y1;
            p[12] = x1l; p[13] = y1
            draw poly image roadImg[i%2], p
        endif
    next
    
    redraw
    fwait 60
wend

Edit Increased the resolution
Reply


Messages In This Thread
Rotated and scaled image drawing - by Marcus - 03-03-2024, 10:49 AM
RE: Rotated and scaled image drawing - by Marcus - 03-03-2024, 08:25 PM
RE: Rotated and scaled image drawing - by Marcus - 03-06-2024, 04:08 PM
RE: Rotated and scaled image drawing - by Marcus - 03-06-2024, 05:01 PM
RE: Rotated and scaled image drawing - by Marcus - 03-06-2024, 06:20 PM
RE: Rotated and scaled image drawing - by Marcus - 03-10-2024, 01:24 PM
RE: Rotated and scaled image drawing - by Marcus - 03-14-2024, 04:38 PM
RE: Rotated and scaled image drawing - by Marcus - 03-14-2024, 07:00 PM
RE: Rotated and scaled image drawing - by Marcus - 03-15-2024, 09:38 PM
RE: Rotated and scaled image drawing - by kevin - 03-16-2024, 01:19 PM

Forum Jump:


Users browsing this thread: 2 Guest(s)