Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / 2D Spaceshooter

Author
Message
Zero Blitzt
21
Years of Service
User Offline
Joined: 18th Jan 2004
Location: Different Stages
Posted: 18th Mar 2004 22:32
I looked at Reaperman's 2D spaceshooter tutorial, didnt get it, and I sat down and started to code, from the top of my head. So far, I made almost an entire game by myself (which really rocks cuz I remember everything), but I'm having a problem with enemy movement. I've attached the source, could someone please help me make my enemies move randomly up and down (and possibly left to right)?

By the Way, anyone can take the source, and redo it for your own game, I dont care, it's not like I have a copyright on it or anything.

http://www.t4e0.4cybiko.com- GameXaero Forums
http://www.t4e0.4cybiko.com/gxstudios - GX Studios
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 19th Mar 2004 00:05
Well you have got the first part of the game working. You can take out the # signs because they are slowing your game down, and you aren't using floats 1.0, 1.2, you are using whole numbers..1 2 3 4 5.
So you don't need them.

You could make a program that stores mouse movements, then plays them back, and you use these mouse movements for enemy patterns. Or you could use maths. I'm not too hot at maths, you will have to search for Cos, and Sin. Funny thing is that Winamp has a plugin called Milkdrop, and if you customise it you will find patterns in there that use Cos, and Sin. You could grab some maths from there. You might find routines in anything.

Zero Blitzt
21
Years of Service
User Offline
Joined: 18th Jan 2004
Location: Different Stages
Posted: 19th Mar 2004 01:30
Cool, thanks, but what is Winamp and where could I get it?

http://www.t4e0.4cybiko.com- GameXaero Forums
http://www.t4e0.4cybiko.com/gxstudios - GX Studios
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 19th Mar 2004 01:48 Edited at: 19th Mar 2004 01:49
It's a music player. It doesn't matter, here's the code. It's not like DB, but the maths should easily be converted. I can understand it, just strip it down.

code_6=x = x - 0.008 + 0.0033*sin(time*1.371);
code_7=y = orig_y + 0.12*sin(time*1.9);



Strip parts out, and you should start to see something you can use.

x = x - 0.008 + 0.0033*sin(time*1.371)
y = orig_y + 0.12*sin(time*1.9)

But I did not mean you to bother with all of this. I was just saying that you should look through code that has things moving up, and down in waves. Any code. Try codebase. Click the top of Apollo.

Zero Blitzt
21
Years of Service
User Offline
Joined: 18th Jan 2004
Location: Different Stages
Posted: 22nd Mar 2004 13:05
I was thinking about it, and couldnt I use


to make the ship move up and down? It wouldnt be random, but it's a start. Please note that that code may not be correct, I have never used "repeat" and "until" as loops yet.

http://www.t4e0.4cybiko.com- GameXaero Forums
http://www.t4e0.4cybiko.com/gxstudios - GX Studios
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 22nd Mar 2004 15:06 Edited at: 22nd Mar 2004 15:06
You can't use repeat until in the middle of a game. It stops everything apart from the enemy. You can use the same code like this...

down = 1

Do
if up = 1
dec enemyY
if enemyY <= 0 then down = 1 : up = 0
endif


if down = 1
inc enemyY
if enemyY >= 100 then up = 1 : down = 0
endif

Loop

Pincho.

UnderLord
21
Years of Service
User Offline
Joined: 2nd Aug 2003
Location:
Posted: 22nd Mar 2004 17:03
Where is this 2d tutorial made by reaperman?

The search continues.

Current project - A space game
Morloc
21
Years of Service
User Offline
Joined: 21st Mar 2004
Location: UK
Posted: 22nd Mar 2004 19:00
go here http://darkbasic.thegamecreators.com/?m=forum_view&t=27598&b=4

its very good as a starting point for most things.

Morloc

Morloc
UnderLord
21
Years of Service
User Offline
Joined: 2nd Aug 2003
Location:
Posted: 22nd Mar 2004 20:08
good i need a starting point for shooting and AI =)

for as long as i code i won't forget how to do 2d movement/speed

The search continues.

Current project - A space game
Zero Blitzt
21
Years of Service
User Offline
Joined: 18th Jan 2004
Location: Different Stages
Posted: 22nd Mar 2004 22:29
Thanks a bunch, you can expect to see my first 2D game *ever* out sometime soon.

http://www.t4e0.4cybiko.com- GameXaero Forums
http://www.t4e0.4cybiko.com/gxstudios - GX Studios
Reaperman
21
Years of Service
User Offline
Joined: 9th Sep 2003
Location: Kent, England
Posted: 23rd Mar 2004 15:01
Glad you found the tutorial helpful.

It does give you a start and while its not a full game, it should point you in the right direction.

As for making attack waves, as I said to Tapewormz, it can be as complex or as easy as you want.
You can combine set movement patterns with a random element so that the user can never quite tell how the enemy will move. As a simple example….. If you have an alien that you want to bounce about the screen, a routine like the following will do it for you:

sync on
sync rate 30
color backdrop 0
hide mouse
load image "alienship.bmp",1
x=320:y=240
asx=1:al=6:a2=10:a3=8:ca=160
sprite 1,x,y,1
do
AM=RND(12)
AMP=RND(20)+10
if am=1 then gosub 1
if am=2 then gosub 2
if am=3 then gosub 3
if am=4 then gosub 4
if am=5 then gosub 5
if am=6 then gosub 6
if am=7 then gosub 7
if am=8 then gosub 8
if am>8 then gosub 6
sync
loop
1:
for t=1 to amp
sprite 1,x,y,1
inc x,2:dec y,2
sync
next t
return
2:
for t=1 to amp
sprite 1,x,y,1
inc x,2:dec y,2
sync
next t
return
3:
for t=1 to amp
sprite 1,x,y,1
inc x,2
sync
next t
return
4:
for t=1 to amp
sprite 1,x,y,1
inc x,2:inc y,2
sync
next t
return
5:
for t=1 to amp
sprite 1,x,y,1
inc y,2
sync
next t
return
6:
for t=1 to amp
sprite 1,x,y,1
dec x,2:inc y,2
sync
next t
return
7:
for t=1 to amp
sprite 1,x,y,1
dec x,2
sync
next t
return
8:
for t=1 to amp
sprite 1,x,y,1
dec x,2:dec y,2
sync
next t
return

(Place this program in the same directory as the 2D Shoot Em Up tutorial)

What it does is to pick a direction using AM (1 to 8... 1=45 degrees upleft: 2 =left: 3=45 degrees downleft: 4=down: 5=45 degrees downright: 6= right: 7=45 degrees upright: 8=up).
We weight it so that there is a better chance of the alien moving forward, by making it pick a number from 0 to 12. Then we pick an amount to move in pixels using AMP.

Then we simply check the value of AM and if it is 1 then we jump to a routine that moves the alien 45 degrees up and to the left.

This example is pure random movement.

You can make it better by putting some other constraints in to it. You may want to check if the alien if going off screen (use the X and Y coordinates) and if it is you may want to bounce it back by using a set routine to move the alien in to a specific direction.

There are many many other things you can do to this routine and I have kept it simple and not compacted it so that its easy to alter.

Hope that some of this helps and remember, the best way to find out how to do something is to mess, mess and then mess some more.
PST
21
Years of Service
User Offline
Joined: 15th Mar 2004
Location:
Posted: 27th Mar 2004 22:08
Reapermen are you some kind of "all knowing geek" ??
Joking, i read your tutorial, but it has no enemies, hasn't it?
Reaperman
21
Years of Service
User Offline
Joined: 9th Sep 2003
Location: Kent, England
Posted: 27th Mar 2004 23:47
Quote: "i read your tutorial, but it has no enemies, hasn't it?"


You are right PST, but I was hoping that it would help newcomers to 2D grasp the basic things that go in to making up a 2D scroller.

Because you asked about enemies, I am just putting the finishing parts in to the tutorial program to make it a one level game...I hope it will help you when I post it here.
Reaperman
21
Years of Service
User Offline
Joined: 9th Sep 2003
Location: Kent, England
Posted: 4th Apr 2004 20:02
Ok PST I have put the full game on line now..... Go here : http://darkbasic.thegamecreators.com/?m=forum_view&t=27598&b=4 to read/download it.

Hope it helps you.
Tapewormz
22
Years of Service
User Offline
Joined: 15th Sep 2002
Location: Winnipeg, Mantoba, Canada
Posted: 6th Apr 2004 01:16
Hey Reaperman,

Do you perfer pasting images or using sprites in your 2D scrollers? My collision routines are all self coded bounding boxes. From there I go a step further and use a subroutine for detecting pixel collision.

Are you currently working on any projects?

Quote: " Timesoft - Your wife is death. How? NO idea.
But it is murder. REVENGE!!!!!!!!!"

Hands down the funniest synopsis for a game ever. All your base are belong to us!
Reaperman
21
Years of Service
User Offline
Joined: 9th Sep 2003
Location: Kent, England
Posted: 6th Apr 2004 02:42
Quote: "Hey Reaperman,

Do you perfer pasting images or using sprites in your 2D scrollers?"


Well Tapewormz, pasting is faster than using a sprite as-is. There is an old trick using something called “Paging� where you can paste the sprites on a hidden page and then “flip� that page into view. You have to hold collision in an array, but depending on the type of game your working on (and the number of sprites) you can make a significant speed increase. However, when it calls for active sprites I prefer to use them as sprites and only use a paste image routine for background or non-action images.

Quote: "My collision routines are all self coded bounding boxes. From there I go a step further and use a subroutine for detecting pixel collision."


Good... Sounds like you have a handle on it. The built in collision routine in Darkbasic is unfortunately slow. However, it does suffice for simple collision or when not wanting pixel perfect/edge collision……And it is the thing most newcomers use anyway. But I have to agree with you that the best way to go is to hand code it yourself.

Quote: "Are you currently working on any projects?"


Yes I am.
I am finishing off an Adventure game for commercial release which is a corroboration with another programmer and an artist. It is connected with E.G.G (European Graphixs Guild) and is an internet team working for the likes of Ian Livingstone and Steve Jackson.
I am also finishing off a series of tutorials (for this site), and away from Darkbasic, I am working with a company on a large release of a real time Adventure based on an Authors book... When I can I will mention it…but I am not allowed to right now.

But...As I always do…If you ever want me to help you with one of your projects, then let me know and I will do my best.

Cheers.
lokatsis
21
Years of Service
User Offline
Joined: 11th Feb 2004
Location: greece
Posted: 7th Apr 2004 14:43
hi Reaperman. i have read your tutorial and i found it great but i have some problem. When i press the "z" key to fire, it always fires the laser from the center of the screen independently the place of the ship .
i'd like to fire the laser exactly from the place of the ship ,can you help me

THE AOOS
Reaperman
21
Years of Service
User Offline
Joined: 9th Sep 2003
Location: Kent, England
Posted: 9th Apr 2004 00:11
lokatsis....

Yes I can.

All you have to do is to add the commands:

lx=SPRITE X(1)+20
ly=SPRITE Y(1)+10

Before the program jumps to the SHOOT: lable.

Sorry for that... I did not see it before.
lokatsis
21
Years of Service
User Offline
Joined: 11th Feb 2004
Location: greece
Posted: 12th Apr 2004 20:03
thanks.

THE AOOS

Login to post a reply

Server time is: 2025-05-15 20:35:51
Your offset time is: 2025-05-15 20:35:51