RE: Rotated and scaled image drawing - 1micha.elok - 03-11-2024
(03-10-2024, 01:24 PM)Marcus Wrote: This graphics set might be of use for a 3d racing game, and I might give it a try: https://opengameart.org/content/25d-racing-resources
Different angles of car sprite ... great
RE: Rotated and scaled image drawing - 1micha.elok - 03-11-2024
(03-10-2024, 01:24 PM)Marcus Wrote: This graphics set might be of use for a 3d racing game, and I might give it a try: https://opengameart.org/content/25d-racing-resources
Today's progress in TFTF.zip
Using the racing resources (opengameart's graphics set)
- Flying object : zeppelin
- Car's player : LEFT, RIGHT, UP
Works to do ... a lot of homeworks for this week
1. Monitoring : street track, dashboard (angle, speed), life, score
2. Background : city and woods
3. Incoming barrier : fence, road barrier, billboard, cliffs, signs, snowman,trees
4. More control : player's speed acceleration
5. Condition : daylight, night, snowy
6. Finish line
In fact, curved road has given me more programming problems to solve than a straight road.
However, "Don't give up", I said to myself.... I still have 4 days before the next weekend
Code: '---------------------------------------
' THE FAST AND THE FURIOUS
'
' Works to do :
' 1. Score, Life
' 2. Moving city and woods as the background
' 3. Incoming barrier : fence, road barrier,
' billboard, cliffs, signs, snowman,trees
' 4. Player's speed acceleration
' 5. Drive at night
' 6. Street track
' 7. Dashboard : angle, speed
' 8. Finish line
'
' Control :
' - mOvement : LEFT, RIGHT, UP
' - quit : ESC
'
' References :
' 1. CURVED ROAD, texture mapping, N7_24.03.05, by Marcus
' 2. Sprites https://opengameart.org/content/25d-racing-resources
'----------------------------------------
'----------------
' INITIALIZATION
'----------------
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]
'Fying object
zepp = []
zepp.img = loadimage("assets/back_zeppelin.png")
zepp.x = width(primary)+100
' -------------- 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 = []
for z = 0 to 200 road[z] = sin(z*0.05)*6
' 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
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
'------------
' MAIN LOOP
'------------
while not keydown(KEY_ESCAPE, true)
'Player
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
'Scene : blue sky, brown earth, zeppelin
set color blue; cls
set color brown; draw rect 0, height(primary)/2+0.03*height(primary), width(primary), height(primary)/2, true
set color white; draw image zepp.img, zepp.x, 50
if zepp.x < - 100 then
zepp.x = width(primary)+100
else
zepp.x = zepp.x -1
endif
'Scene : animated road
set color white
for i = int(player.z) + 20 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
'night road
'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
'Draw player
set color white; draw image player.img,width(primary)/2-width(player.img)/2,height(primary)-110,player.cell
redraw
fwait 60
wend
'-----------
' FUNCTIONS
'-----------
RE: Rotated and scaled image drawing - johnno56 - 03-11-2024
Nice start! I only had one itsy-bitsy, teeny-weeny, problem... I ran out of road... lol Nicely done!
RE: Rotated and scaled image drawing - 1micha.elok - 03-12-2024
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
RE: Rotated and scaled image drawing - johnno56 - 03-12-2024
Moving scenery? Nice touch...
Small suggestion. Two key presses for changing direction. Left and Right. Rather than pressing the Up key to "straighten" the car, perhaps make it that if the Left or Right key is NOT pressed then return the car "cell" to 3? That way you can reserve the Up and Down keys to control the speed etc...
3 days? You have set a time limit? Interesting.
RE: Rotated and scaled image drawing - 1micha.elok - 03-13-2024
(03-12-2024, 06:29 PM)johnno56 Wrote: Moving scenery? Nice touch...
Small suggestion. Two key presses for changing direction. Left and Right. Rather than pressing the Up key to "straighten" the car, perhaps make it that if the Left or Right key is NOT pressed then return the car "cell" to 3? That way you can reserve the Up and Down keys to control the speed etc...
3 days? You have set a time limit? Interesting.
click the image to zoom in
Progress Day 3
- Add background rock music (looping)
- Add sound effect for car's acceleration
- No more KEY_W or KEY_S for acceleration
- LEFT and RIGHT for changing direction and in 0.5 second would return to normal position (cell 3) or "straighten" automatically
- KEY UP to accelerate the car and deaccelerate automatically .... whaaaat ?
- Add a nice circle Speedometer
Next
- Incoming barriers (fence, dirt etc.) perhaps these are the most challenging to code
- Street / Race Track
Remaining Days to Finish The Game
- 2 days before this weekend .... aaarrrggghhh... I lost a lot of my hairs ....
I have set a time limit for my personal reason only, so that this project would not be a "Never ending story"
Code: '---------------------------------------
' THE FAST AND THE FURIOUS - DAY 3
'
' Works to do :
' 1. Incoming barrier : fence, road barrier,
' billboard, cliffs, signs, snowman,trees
' if hit barrier Life = Life - 1
' 2. street track
'
' Control :
' - movement : LEFT, RIGHT
' - speed : UP, DOWN
' - quit : ESC
'
' Note :
' This game is just a proof of concept.
' The duration is very short.
' You may extend the length of the road
' Find this variable to change : road.length = 120
'
' References :
' 1. CURVED ROAD, texture mapping, N7_24.03.05, by Marcus
' 2. Sprites https://opengameart.org/content/25d-racing-resources
' 3. Sound Effect and Music https://pixabay.com
'----------------------------------------
'----------------
' INITIALIZATION
'----------------
'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]
red = [255,0,0]
'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
background.music_ = loadmusic("assets/rock.wav")
' -------------- 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 'default value = 120
for z = 0 to road.length
road[z] = sin(z*0.05)*2
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 = []
barrier[1] = loadimage("assets/barrier_fence.png")
barrier[2] = loadimage("assets/barrier_road.png")
barrier[3] = loadimage("assets/barrier_trash.png")
barrier[4] = loadimage("assets/side_billboard.png")
barrier[5] = loadimage("assets/side_cliff.png")
' 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
player.gas = loadsound("assets/acceleration.wav")
'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")
info.timeStart = 0; info.timeDuration = 0 'timer's variables
play music background.music_,1 'looping
'------------
' 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
info.timeStart = clock()
elseif keydown(KEY_RIGHT,true) then
player.x = player.x + 0.1
player.cell =0
info.timeStart = clock()
endif
info.timeDuration = (clock() - info.timeStart)/1000
if info.timeDuration > 0.5 then player.cell = 3
if keydown(KEY_UP,true) and player.speed <=80 then
player.speed = player.speed+10
play sound player.gas,1
elseif keydown(KEY_DOWN,true) and player.speed >=20 then
player.speed = player.speed-10
endif
if player.speed > 10 then player.speed = player.speed - 0.2
'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";set caret 300,5; wln "Speed: "+round(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
'Dashboard : Speedometer
angle = player.speed/10*30
set color white; draw ellipse 50,110-30,40,40 ; draw ellipse 50,110-30,41,41
set color red ; draw ellipse 50,110-30,5,5,1
draw line 49,109-30, 49+30*cos(rad(80+angle)),109-30+30*sin(rad(80+angle))
draw line 50,110-30, 50+30*cos(rad(80+angle)),110-30+30*sin(rad(80+angle))
draw line 51,111-30, 51+30*cos(rad(80+angle)),111-30+30*sin(rad(80+angle))
'Draw player
set color white; draw image player.img,width(primary)/2-width(player.img)/2,height(primary)-110,player.cell
redraw
'Time is Up
if i >= sizeof(road) - 20 then
draw image info.finish,(width(primary)-width(info.finish))/2,80;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
RE: Rotated and scaled image drawing - johnno56 - 03-13-2024
Nice improvements... Clever use of the accelerator... Slows down when you take your "foot" off... Cool...
Deadlines are a good idea... as long as they are realistic... If you think you can finish in two days, cool... Not many people like a "never ending story" but there is nothing wrong with the story being told over several volumes... Like Lord of the rings...
Remember... If you are not having fun, you maybe doing it wrong... lol
Good lick...
RE: Rotated and scaled image drawing - 1micha.elok - 03-14-2024
(03-13-2024, 11:18 AM)johnno56 Wrote: .. Like Lord of the rings... Lord of the Rings...mmm... you've just given me an idea to make an old RPG style with the characters from the Lord of the Rings
Thank you for your advice.
Progress Day 4
click the image to zoom in
- Added moving traffic signs on the left side of the road
- Added moving trees on the right side of the road
- Eight-Shape Road track with player's position along the track
- Press S to silent (music and sound effect)
Next
Only 1 remaining day to finish the game
- Collision detection with the traffic signs or trees
- Update Life if collision is detected
Code: '---------------------------------------
' THE FAST AND THE FURIOUS - DAY 4
'
' Control :
' - movement : LEFT, RIGHT
' - speed : UP, DOWN
' - quit : ESC
' - music,sound off : S
'
' Note :
' This game is just a proof of concept.
' The duration of the game is very short.
' You may extend the length of the road by changing the value of road.length
'
' References :
' 1. CURVED ROAD, texture mapping, N7_24.03.05, by Marcus
' DrawImageTransform() function by Marcus
' 2. Sprites https://opengameart.org/content/25d-racing-resources
' 3. Sound Effect and Music https://pixabay.com
'----------------------------------------
'----------------
' INITIALIZATION
'----------------
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]
red = [255,0,0]
green = [0,255,0]
'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
free image city 'remove from memory
free image woods
background.dx = 0
background.music_ = loadmusic("assets/rock.wav")
' -------------- 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 'default value = 120
for z = 0 to road.length
road[z] = sin(z*0.05)*2
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
barrier = []
barrier[1] = []
barrier[2] = []
barrier[1].img = loadimage("assets/side_sign.png")
barrier[2].img = loadimage("assets/side_tree.png")
' 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
player.gas = loadsound("assets/acceleration.wav")
'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")
info.timeStart = 0; info.timeDuration = 0 'timer's variables
play music background.music_,1 'looping
playsound = 1
'------------
' MAIN LOOP
'------------
while not keydown(KEY_ESCAPE, true)
'Music and Sound control
if keydown(KEY_S,true) then
stop music background.music_
free music background.music_
playsound=0
endif
'Player's Control
player.z = player.z + 0.075
if keydown(KEY_LEFT,true) then
player.x = player.x - 0.1
player.cell =6
info.timeStart = clock()
elseif keydown(KEY_RIGHT,true) then
player.x = player.x + 0.1
player.cell =0
info.timeStart = clock()
endif
info.timeDuration = (clock() - info.timeStart)/1000
if info.timeDuration > 0.5 then player.cell = 3
if keydown(KEY_UP,true) and player.speed <=80 then
player.speed = player.speed+10
if playsound=1 then; play sound player.gas,1; endif
elseif keydown(KEY_DOWN,true) and player.speed >=20 then
player.speed = player.speed-10
endif
if player.speed > 10 then player.speed = player.speed - 0.2
'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
'Distance, Life, Road Track
set color white ; set font info.myfont
distance = (i*10)
set caret 250,5; wln "Distance: "+ distance +" Km"
set caret 5,5; wln "Speed: "+round(player.speed)
set caret width(primary)-90,5; wln "Life : "+info.life
'calculate the car's position on the road track
'ratio of (current distance/total distance) times 360 degree
cd = distance/1010*360
'Road Track
for d = 0 to 360
t = rad(180-d)
posx = 60*sin(t) + width(primary)/2
posy = 60*sin(t)*cos(t) + 80
set color white; draw pixel posx,posy
'draw car's position on the road track
tcd = rad(180-cd)
posxcd = 60*sin(tcd) + width(primary)/2
posycd = 60*sin(tcd)*cos(tcd) + 80
set color green; draw ellipse posxcd,posycd,5,5,1
next
'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
'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 road
set color white; draw poly image roadImg[i%2], p
'Draw barriers
if z >= 0.5 then
sf = 1/z+0.3 'scale factor
barrier[1].x = x0l-20; barrier[1].y = y0
barrier[2].x = x0r+10; barrier[2].y = y0
if i%10 = 0 then
Draw(barrier[1].img, barrier[1].x, barrier[1].y, sf)
else
barrier[1].y = -10
barrier[1].x = -10
endif
if i%2 = 0 then
Draw(barrier[2].img, barrier[2].x, barrier[2].y, sf)
else
barrier[2].y = -10
barrier[2].y = - 10
endif
endif
endif
next
'Dashboard : Speedometer
angle = player.speed/10*30
set color white; draw ellipse 50,110-30,40,40 ; draw ellipse 50,110-30,41,41
set color red ; draw ellipse 50,110-30,5,5,1
draw line 49,109-30, 49+30*cos(rad(80+angle)),109-30+30*sin(rad(80+angle))
draw line 50,110-30, 50+30*cos(rad(80+angle)),110-30+30*sin(rad(80+angle))
draw line 51,111-30, 51+30*cos(rad(80+angle)),111-30+30*sin(rad(80+angle))
'Draw player
set color white; draw image player.img,width(primary)/2-width(player.img)/2,height(primary)-110,player.cell
redraw
'Time is Up
if i >= sizeof(road) - 20 or info.life <= -1 then
draw image info.finish,(width(primary)-width(info.finish))/2,120;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 = 0; py = height(img)
DrawImageTransformed(img, x,y, s, s, a, px, py)
endfunc
RE: Rotated and scaled image drawing - Marcus - 03-14-2024
Looking really good, great work!
RE: Rotated and scaled image drawing - johnno56 - 03-14-2024
Agreed... Looking good!
An amusing side note: (well... I thought it was funny...)
That is one powerful car! The race, for me, lasted for less than a minute... But I maxed out my speed to about 84kph but managed to travel more that 1000km... If my math is correct, and it usually is not, that would mean my actual speed would be about 12,000kph... 30 seconds = distance of 1000; 1 minute = 2000; 1 hour = 2000 X 60... as I said, "One powerful car". The only thing missing is the "Flux Capacitor"... Moo Ha Ha Ha....
|