return movement - aliensoldier - 05-20-2024
In the first level there are those mechanical birds that move from left to right but at any moment they launch themselves towards the player and then return to their initial position. How can you make them return to their initial position with that motion?
RE: return movement - Marcus - 05-20-2024
(05-20-2024, 02:47 PM)aliensoldier Wrote:
In the first level there are those mechanical birds that move from left to right but at any moment they launch themselves towards the player and then return to their initial position. How can you make them return to their initial position with that motion?
I believe I or Kevin or both posted an example of that in this thread: https://www.naalaa.com/forum/thread-90.html, hope it helps!
RE: return movement - aliensoldier - 05-20-2024
(05-20-2024, 03:27 PM)Marcus Wrote: (05-20-2024, 02:47 PM)aliensoldier Wrote:
In the first level there are those mechanical birds that move from left to right but at any moment they launch themselves towards the player and then return to their initial position. How can you make them return to their initial position with that motion?
I believe I or Kevin or both posted an example of that in this thread: https://www.naalaa.com/forum/thread-90.html, hope it helps!
I'll see if I can find it , it would be nice in future versions of naalaa to include more examples of the polyline library.
RE: return movement - kevin - 05-21-2024
Phoenix!!!! I just loved the arcade version of this game. I actually started to code a clone of this a few months ago, but abandoned it when I lost interest (this happens a lot ).
I'll try to find it a little later in case it helps - I'm pretty sure it had the enemies diving and returning to thier original positions that you were asking about.
All the best - Kevin.
RE: return movement - kevin - 05-21-2024
(05-21-2024, 04:37 AM)kevin Wrote: Phoenix!!!! I just loved the arcade version of this game. I actually started to code a clone of this a few months ago, but abandoned it when I lost interest (this happens a lot ).
I'll try to find it a little later in case it helps - I'm pretty sure it had the enemies diving and returning to thier original positions that you were asking about.
All the best - Kevin.
Here's the example I referred to above. It uses the "return" code that Marcus provided back in March. It makes 3 of the invaders dive down, and then return to their original positions - you can change the number of diving invaders in lines 121 onwards.
Please bear in mind that this is by no means a finished program - very much a work in progress. Any questions, please ask and I will try to answer them.
phoenix dive example.zip (Size: 1.07 MB / Downloads: 6)
RE: return movement - johnno56 - 05-21-2024
Losing interest? I know the feeling oh too well... But still... Cool game... Reminds me of Galaga...
RE: return movement - aliensoldier - 05-21-2024
(05-21-2024, 07:44 AM)kevin Wrote: (05-21-2024, 04:37 AM)kevin Wrote: Phoenix!!!! I just loved the arcade version of this game. I actually started to code a clone of this a few months ago, but abandoned it when I lost interest (this happens a lot ).
I'll try to find it a little later in case it helps - I'm pretty sure it had the enemies diving and returning to thier original positions that you were asking about.
All the best - Kevin.
Here's the example I referred to above. It uses the "return" code that Marcus provided back in March. It makes 3 of the invaders dive down, and then return to their original positions - you can change the number of diving invaders in lines 121 onwards.
Please bear in mind that this is by no means a finished program - very much a work in progress. Any questions, please ask and I will try to answer them.
Thanks for the example Kevin.
But it is too complicated for me and I can't understand it, the only way I could understand it would be to create an example where there is only one enemy, who after a few seconds moves down and after a few seconds returns to his initial position.
For the code to be as simple as possible, it would be best to only have the code of that enemy and nothing else, this way you could study more clearly what the code does. No matter how much time passes, I still don't understand well when there is a lot code, sorry for my clumsiness.
RE: return movement - kevin - 05-22-2024
Thanks for the example Kevin.
But it is too complicated for me and I can't understand it, the only way I could understand it would be to create an example where there is only one enemy, who after a few seconds moves down and after a few seconds returns to his initial position.
For the code to be as simple as possible, it would be best to only have the code of that enemy and nothing else, this way you could study more clearly what the code does. No matter how much time passes, I still don't understand well when there is a lot code, sorry for my clumsiness.
I fully understand. Hope this is better for you - it is based on Marcus's solution to my question on this subject from last March.
Code: include "polyline.n7"
visible screen_w = 640,screen_h = 480
'Open a window
set window "Diving example",screen_w,screen_h
'enable double buffering
set redraw off
invader = [x:300,y:50,dx:1,w:32,h:16,dive_x:unset,dive_y:unset,diving:false]
##############################################################################################
####################################### GAME LOOP #########################################
##############################################################################################
do
'release the invader occasionally
timer = (timer + 1 ) % 500
if timer = 499
invader.diving = true
' This is the additional code provided by Marcus back in March
' Very simple path, just dive to the bottom center of the screen and back again.
invader.path = PolyLine([[invader.x, invader.y], [width(primary)/2, height(primary) - 20], [invader.x, invader.y]],false)
' Set traveled distance to 0.
invader.path_dist = 0
' We still need to update the diver's regular position. So when diving, the invader's position is
' stored in dive_x, dive_y. Use these coordinates when drawing and doing collision tests for a
' diving invader.
invader.dive_x = invader.x
invader.dive_y = invader.y
' EndMarcus
endif
'move the invader and keep it on screen
invader.x = invader.x + invader.dx
if invader.x > 600 or invader.x < 40 then invader.dx = - invader.dx
' Marcus code
if invader.diving = true
' Set the last control point of the path to the invaders normal position.
' A problem here is that the regular invaders move vertically with huge steps. This
' doesn't look good for the movement of a diver. So rather than doing this:
'invaders[i].path.ModifyControlPoint(2, invaders[i].x, invaders[i].y)
' , we can interpolate the y coordinate:
y = invader.path.GetControlPoint(2)[1] ' current y of the last control point.
invader.path.ModifyControlPoint(2, invader.x, y*0.95 + invader.y*0.05)
' Move 4 pixels.
invader.path_dist = invader.path_dist + 4
pos = invader.path.GetPoint(invader.path_dist, true)
' Still on path?
if pos
invader.dive_x = pos[0]
invader.dive_y = pos[1]
' No longer diving.
else
invader.diving = false
endif
endif
' EndMarcus
'clear the screen
set color 255,255,255
cls
set color 0,0,0
'draw the invader as a solid rectangle - only show an outline when diving to see
'where the original path would have been
if invader.diving = false
draw rect invader.x,invader.y,invader.w,invader.h,true
else
draw rect invader.x,invader.y,invader.w,invader.h,false
draw rect invader.dive_x,invader.dive_y,invader.w,invader.h,true
endif
'copy back buffer to the screen
redraw
'cap FPS to 60
fwait 60
until keydown(KEY_ESCAPE)
RE: return movement - aliensoldier - 05-22-2024
(05-22-2024, 05:13 AM)kevin Wrote: Thanks for the example Kevin.
But it is too complicated for me and I can't understand it, the only way I could understand it would be to create an example where there is only one enemy, who after a few seconds moves down and after a few seconds returns to his initial position.
For the code to be as simple as possible, it would be best to only have the code of that enemy and nothing else, this way you could study more clearly what the code does. No matter how much time passes, I still don't understand well when there is a lot code, sorry for my clumsiness.
I fully understand. Hope this is better for you - it is based on Marcus's solution to my question on this subject from last March.
Code: include "polyline.n7"
visible screen_w = 640,screen_h = 480
'Open a window
set window "Diving example",screen_w,screen_h
'enable double buffering
set redraw off
invader = [x:300,y:50,dx:1,w:32,h:16,dive_x:unset,dive_y:unset,diving:false]
##############################################################################################
####################################### GAME LOOP #########################################
##############################################################################################
do
'release the invader occasionally
timer = (timer + 1 ) % 500
if timer = 499
invader.diving = true
' This is the additional code provided by Marcus back in March
' Very simple path, just dive to the bottom center of the screen and back again.
invader.path = PolyLine([[invader.x, invader.y], [width(primary)/2, height(primary) - 20], [invader.x, invader.y]],false)
' Set traveled distance to 0.
invader.path_dist = 0
' We still need to update the diver's regular position. So when diving, the invader's position is
' stored in dive_x, dive_y. Use these coordinates when drawing and doing collision tests for a
' diving invader.
invader.dive_x = invader.x
invader.dive_y = invader.y
' EndMarcus
endif
'move the invader and keep it on screen
invader.x = invader.x + invader.dx
if invader.x > 600 or invader.x < 40 then invader.dx = - invader.dx
' Marcus code
if invader.diving = true
' Set the last control point of the path to the invaders normal position.
' A problem here is that the regular invaders move vertically with huge steps. This
' doesn't look good for the movement of a diver. So rather than doing this:
'invaders[i].path.ModifyControlPoint(2, invaders[i].x, invaders[i].y)
' , we can interpolate the y coordinate:
y = invader.path.GetControlPoint(2)[1] ' current y of the last control point.
invader.path.ModifyControlPoint(2, invader.x, y*0.95 + invader.y*0.05)
' Move 4 pixels.
invader.path_dist = invader.path_dist + 4
pos = invader.path.GetPoint(invader.path_dist, true)
' Still on path?
if pos
invader.dive_x = pos[0]
invader.dive_y = pos[1]
' No longer diving.
else
invader.diving = false
endif
endif
' EndMarcus
'clear the screen
set color 255,255,255
cls
set color 0,0,0
'draw the invader as a solid rectangle - only show an outline when diving to see
'where the original path would have been
if invader.diving = false
draw rect invader.x,invader.y,invader.w,invader.h,true
else
draw rect invader.x,invader.y,invader.w,invader.h,false
draw rect invader.dive_x,invader.dive_y,invader.w,invader.h,true
endif
'copy back buffer to the screen
redraw
'cap FPS to 60
fwait 60
until keydown(KEY_ESCAPE)
Thank you Kevin.
This example is much easier to study. I think that Naalaa should have more short examples like this that teach different game mechanics and useful tricks but always with super short examples so that everyone can study them easily. Greetings
RE: return movement - kevin - 05-22-2024
No problem. Most of the functions already have good examples that are accessed by pressing the F1 key when the cursor is located on the keyword of course, but if you have specific things that you want an example of, please ask. I'm sure someone will try to help if they can ....I certainly will if I have the time, and know the answer
|