12-20-2023, 03:50 AM
(12-14-2023, 06:45 AM)johnno56 Wrote: ...
If you have any difficulties or questions just ask... If I do not know the answer I am sure that someone else on this site will know... lol
...
Hi Johnno56,
Your source code of Space Race in Naalaa is very useful for me as a reference to study the logic of the game.
Just for fun, I made some modifications
1. The program structure is grouped into 3 categories :
- INITIALIZATION : set up windows, variables
- MAIN PROGRAM : do ... loop
- FUNCTIONS
InitObjects()
GameIntro()
MoveRocks()
DisplayPlayers()
PlayersMovement()
CalculateScore()
2. Using Dot notation
Code:
function InitObjects()
'computer player
player.x = 60;
player.y = 300;
player.w = 15;
player.h = 16
'human player
player2.x = 165;
player2.y = 300;
player2.w = 15;
player2.h = 16
...
endfunc
3. It is a simplified version
i.e.Rocks only move from left to right
i.e.Human Player vs Computer Player (only move forward, most of the time it hits the rocks )
Code:
function PlayersMovement()
'Computer Player (Auto movement)
player.y = player.y - (0.1*rnd(10))
if player.y <= -15
score1 = score1 + 1; player.y = 300
endif
'Human Player
if keydown(KEY_UP)
player2.y = player2.y - 1
if player2.y <= -15
score2 = score2 + 1; player2.y = 300
endif
endif
if keydown(KEY_DOWN)
player2.y = player2.y + 1
if player2.y > 300
player2.y = 300
endif
endif
endfunc
Once again, thanks to Johnno56 for having shared the source code of Space Race in Naalaa