Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rotated and scaled image drawing
#14
Progress Day 2
- Distance   ( limited distance to finish line)
- Life           ( display only at the moment )
- Speed       ( press W to accelerate, S to deaccelerate )
- Moving background (city, woods)

   
click the image to zoom in

Works to do 
 1. Incoming barrier : fence, road barrier,
        billboard, cliffs, signs, snowman,trees
        if hit barrier Life = Life - 1
 2. Dashboard : speed
 3. street track

note : since I have only 3 days before this weekend to finish the game, I reduce my scope of work in the "works to do" list.

Code:
'---------------------------------------
' THE FAST AND THE FURIOUS
'
' Works to do :
' 1. Incoming barrier : fence, road barrier,
'        billboard, cliffs, signs, snowman,trees
'        if hit barrier Life = Life - 1
' 2. Dashboard : speed
' 3. street track
'
' Control :
' - movement : LEFT, RIGHT, UP
' - speed    : W,S
' - quit     : ESC
'
' References :
' 1. CURVED ROAD, texture mapping, N7_24.03.05, by Marcus
' 2. Sprites https://opengameart.org/content/25d-racing-resources
'----------------------------------------


'----------------
' INITIALIZATION
'----------------
#win32
'include "assets/transform.n7"
set window "The Fast and The Furious", 640, 400, false
set redraw off

'Color definition
blue        = [64, 64, 128]
brown       = [200, 128, 64]
white       = [255, 255, 255]
magenta     = [255,0,255]

'Background city and woods
city = loadimage("assets/back_city.png")
woods = loadimage("assets/back_woods.png")
background = []
background.img = createimage(width(city)*3*20,63)
set image background.img
set color blue;cls;set color white
for i = 0 to 60 step 3
    draw image woods,0+i*width(city),0
    draw image city,width(city)+i*width(city),0
    draw image woods,2*width(city)+i*width(city),0
next
set image primary
background.dx = 0

' -------------- Road Textures ------------
roadImg = []
' First textures
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 white
draw rect 0, 0, 8, 16, true
draw rect 152, 0, 8, 16, true
set image primary

' Second textures
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 white
draw rect 76, 0, 8, 16, true
set image primary
' ------------------------------------------

' Curved Road
road = []
road.length = 120
for z = 0 to road.length 
    road[z] = sin(z*0.05)*2
    pln road[z]
next

'Road
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

'Barrier : fence, road barrier, billboard, cliffs, signs, snowman,trees
barrier = []

' Player
player = []
player.img = loadimage("assets/car_player.png",7,1)
player.cell = 3 '0=right, 6=left, 3=normal
player.z = 0.0
player.x = 0
player.speed = 10 '10=slowest, 120=fastest

'Score, Life, Finish Line
info = []
info.myfont = createfont("Arial",30,1,0,0,0)'name,size,bold,italic,underlined,smoothed
info.life = 3
info.finish = loadimage("assets/finish.png")

'------------
' MAIN LOOP
'------------
while not keydown(KEY_ESCAPE, true)

    'Player's Control
    player.z = player.z + 0.075
    if keydown(KEY_LEFT,true) then
         player.x = player.x - 0.1
         player.cell =6
    elseif keydown(KEY_RIGHT,true) then
         player.x = player.x + 0.1
         player.cell =0
    elseif keydown(KEY_UP,true) then
         player.cell =3
    endif
   
    if keydown(KEY_W,true) and player.speed <=110 then
        player.speed = player.speed+10
    endif
    if keydown(KEY_S,true) and player.speed >=20 then
        player.speed = player.speed-10
    endif   

    'Scene : blue sky, brown earth
    set color blue; cls
    set color brown; draw rect 0, height(primary)/2+0.03*height(primary), width(primary), height(primary)/2, true       
                                                                       
    'Scene : animated road
    set color white
    for i = int(player.z) + 15 to int(player.z)
        if i < sizeof(road) - 2
            z = i + 1 - player.z + 1.1
            x0l = width(primary)/2 + (0.75*width(primary)-0.125*width(primary))*(road[i + 1] - 1 - player.x)/z
            x0r = width(primary)/2 + (0.75*width(primary)-0.125*width(primary))*(road[i + 1] + 1 - player.x)/z
            y0 = height(primary)/2 + (height(primary)/2+0.04*height(primary))/z
         
            z = i - player.z + 1.1
            x1l = width(primary)/2 + (0.75*width(primary)-0.125*width(primary))*(road[i] - 1 - player.x)/z
            x1r = width(primary)/2 + (0.75*width(primary)-0.125*width(primary))*(road[i] + 1 - player.x)/z
            y1 = height(primary)/2 + (height(primary)/2+0.04*height(primary))/z

            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

    'Distance, Life
    set color white ; set font info.myfont
    distance = (i*10)
    set caret 5,5; wln "Distance: "+ distance +" Km";wln "Speed: "+player.speed
    set caret width(primary)-90,5; wln "Life : "+info.life       

    'Background : city, woods
    if distance < 450 then
        background.dx = background.dx + 2
    else
        background.dx = background.dx - 2
    endif   
    set color white
    draw image background.img,(-width(background.img)/2)+background.dx,height(primary)/2-50
   
    'Draw player
    set color white; draw image player.img,width(primary)/2-width(player.img)/2,height(primary)-110,player.cell
    redraw

    'Finish Line
    if i >= sizeof(road) - 20 then
        draw image info.finish,(width(primary)-width(info.finish))/2,50;redraw
        while not keydown(KEY_ESCAPE,true);wait 1; wend
        end   
    endif
   
    fwait player.speed 
wend


'-----------
' FUNCTIONS
'-----------
'function Draw(img,x,y,s)
    ' DrawImageTransformed(image, x, y, scale_x, scaleY, angle, pivot_x, pivot_y)
    ' Parameter :
    '   image               = .png format
    '   (x,y)               = location of the image in the screen coordinates
    '   scale_x, scale_y    = scale the image's size
    '   angle               = in radian.
    '   (pivot_x, pivot_y)  = center point of the image. E.g:(0,0) = top left.
'    x = x; y = y ; s = s; a = 0
'    px = width(img)/2; py = height(img)/2
'    DrawImageTransformed(img, x,y, s, s, a, px, py)
'endfunc


Attached Files
.zip   TFTF_Day2.zip (Size: 140.38 KB / Downloads: 5)
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 1micha.elok - 03-12-2024, 11:57 AM
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: 1 Guest(s)