Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PolyLine library
#19
(03-09-2024, 02:53 AM)1micha.elok Wrote:
(03-08-2024, 08:21 PM)Marcus Wrote: I've made some changes to the polyline library so that you can create closed paths.
... writing code while watching a film on tv Smile
 ... use 'atan2(dir[1], dir[0])' to get the angle ...

Last night I watched Gran Tourismo : A True Story, a video game player who became a professional real race car driver. Who knows that for the rest of my life, I could be a professional real race car driver too if I could make a car racing game  Big Grin ...just kidding...

With the changes in the polyline library especially the ability to get the angle 'atan2(dir[1], dir[0])' , you give me an idea to make car's dashboard for the car race game. The left dashboard for the angle direction, and the right dashboard for the car's speed.

click the image to zoom in

Code:
'===============================================
'                 TEST DRIVE
'
'Required : NEW POLYLINE LIBRARY
'===============================================

'------------------
'  INITIALIZATION
'------------------
set console oFF
include "polyline.n7"

set window "Test Drive", 160, 120,false,5
set redraw off

'color definition
white       = [255,255,255]
gray        = [128,128,128,50]
black       = [0,0,0]
black_alpha = [0,0,0,24]
red         = [255,0,0]
green       = [0,255,0]

'points' coordinates
points = []
points[0] = [20,60]
points[1] = [50,30]
points[2] = [80,60]
points[3] = [110,90]
points[4] = [140,60]
points[5] = [110,30]
points[6] = [80,60]
points[7] = [50,90]

' Variables
distance    = 1
move_pixel  = 6
radius      = 2

' Create a polyline
closed_path = true
path = PolyLine(points,closed_path)


'-------------
'  MAIN LOOP
'-------------
while not keydown(KEY_ESCAPE, true)
    ' Title
    set caret width(primary)/2, 6; center "Test Drive"
    if closed_path = true then; cp="true";else;cp="false";endif
    set caret width(primary)/2, height(primary)-20; center "closed "+cp
   
    ' Racing Track
    set color gray  ; draw ellipse 50-1,60, 32,32,1;draw ellipse 110+2,60, 32,32,1
    set color black ; draw ellipse 50-1,60, 21,21,1;draw ellipse 110+2,60, 21,21,1
    set color white ; set caret 20-8,60-6; wln "x"

    'Polyline functions : .GetLength(), .GetPoint(), .GetDirection()
    distance = (distance + move_pixel)%path.GetLength()
    pos = path.GetPoint(distance,true) 'false = sharp, true = curved
    dir = path.GetDirection(distance, true)

    'Car's Dashboard
    'Left Dashboard : Angle
    angle = atan2(dir[1], dir[0])
    set color red; draw line 49,60,18*cos(angle)+49,18*sin(angle)+60
    'Right Dashboard : move_pixel
    speedx = 18*cos(rad(360-30*move_pixel))+112
    speedy = 18*sin(rad(360-30*move_pixel))+60
    draw line 112,60, speedx, speedy  
    if move_pixel < 0 then; move_pixel = 6 ;else;move_pixel = move_pixel - 0.1;endif

    ' Draw circle that moves along path.
    set color black_alpha; cls 'clear background screen
    set color green; draw ellipse pos[0], pos[1], radius, radius, 1

    redraw
    fwait 10
wend

Perhaps, this dashboard and this race track could improve this game visually https://naalaa.com/forum/thread-92-post-539.html#pid539 along with improving the road ( to make a playable curved road ) ... a lot of homeworks  Big Grin

By the way, happy weekend and hope you and your family enjoy the gymnastics competition this weekend too

I once wrote a Mario Kart clone (just a test, more of an engine, I guess) in n5 or n6: https://youtu.be/Xr_UhCX9ta0?si=YPMi7_CBVAJVJRKm&t=212  For that game I actually did use something like the polyline library for the computer players' movements. I "recorded" (saved a position into an array every second or so) my self playing the game a couple of times. Then I let the computer played opponents follow these paths. The enemies could still collide with the eachother and the player, but they always tried to get back on their paths. It worked quite well Smile
Reply


Messages In This Thread
PolyLine library - by Marcus - 02-29-2024, 04:25 PM
RE: PolyLine library - by aliensoldier - 02-29-2024, 04:54 PM
RE: PolyLine library - by kevin - 03-01-2024, 11:32 AM
RE: PolyLine library - by Marcus - 03-01-2024, 02:40 PM
RE: PolyLine library - by kevin - 03-01-2024, 03:02 PM
RE: PolyLine library - by Marcus - 03-01-2024, 06:32 PM
RE: PolyLine library - by kevin - 03-01-2024, 08:05 PM
RE: PolyLine library - by Marcus - 03-02-2024, 01:23 PM
RE: PolyLine library - by johnno56 - 03-01-2024, 09:36 PM
RE: PolyLine library - by Marcus - 03-01-2024, 10:03 PM
RE: PolyLine library - by kevin - 03-02-2024, 04:48 PM
RE: PolyLine library - by Marcus - 03-02-2024, 06:20 PM
RE: PolyLine library - by 1micha.elok - 03-05-2024, 06:53 AM
RE: PolyLine library - by kevin - 03-05-2024, 08:42 AM
RE: PolyLine library - by 1micha.elok - 03-05-2024, 11:15 AM
RE: PolyLine library - by Marcus - 03-05-2024, 08:52 PM
RE: PolyLine library - by Marcus - 03-08-2024, 08:21 PM
RE: PolyLine library - by 1micha.elok - 03-09-2024, 02:53 AM
RE: PolyLine library - by Marcus - 03-09-2024, 07:43 AM
RE: PolyLine library - by Marcus - 03-10-2024, 10:10 AM
RE: PolyLine library - by 1micha.elok - 03-11-2024, 12:52 AM

Forum Jump:


Users browsing this thread: 7 Guest(s)