03-11-2024, 09:33 AM
(This post was last modified: 03-12-2024, 11:45 AM by 1micha.elok.)
(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
'-----------