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! / Scrolling shooting game

Author
Message
Kelz
21
Years of Service
User Offline
Joined: 7th Apr 2005
Location: At the computer
Posted: 28th Jun 2005 06:58
I'm fairly new to DBPro and have completed most of the 3d tutorials. I would really like to be able to program something that isn't moving a sphere around some cubes.
I thought about what i could do and i thought i could make a scrolling game (like Raptor© if anyone knows this game(quite old)) where you fly an aircraft from birds-eye-view and shoots enemies that appear at the top of the screen an fly downwards.
I figured i'd start by looking at how to move the background map and make the screen (your view) move up the map and when you got to the end you'd meet a boss.
I thought this might be something simple to start with but i looked at some of the code that people have posted and i'm absolutely lost. Can anyone help me, or maybe suggest something more simple to make to start with?
gpex
21
Years of Service
User Offline
Joined: 29th May 2005
Location:
Posted: 28th Jun 2005 08:08
well, a classic to start with is pong. Thats what i started with. It's simple in the fact that it is 2d and you dont worry with too many graphics.But at the same time it gives you a chance to work with simple physics.


-gpex-

http://gpex.12.forumer.com/

ex-socom glitcher...
Kelz
21
Years of Service
User Offline
Joined: 7th Apr 2005
Location: At the computer
Posted: 29th Jun 2005 02:56
I did look at the pong tutorial but its for 3d, i'm looking at something else i've managed to find but suggestions are still welcome
Kelz
21
Years of Service
User Offline
Joined: 7th Apr 2005
Location: At the computer
Posted: 29th Jun 2005 21:45 Edited at: 29th Jun 2005 21:45
Okay i've decided to make a pong-type game (in 2D) but i'm not sure on how to start.
Can i use a sprite for the paddle? and i forget... do sprites have to be bitmaps?

If its possible i'd like a hand getting started then as i complete each bit if i get stuck i'll ask for help
What I mean by a pong-type game is one where instead of batting a ball agaist an opponent, you would bat a ball to clear a level of blocks by hitting them.

Another question i'd like to ask is how to make a menu using an image... I'm sure this must be posted elsewhere I had a look, but couldn't find anything useful, if anyone knows of a thread that could answer my question then could you please tell me where to find it
NanoBrain
21
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 30th Jun 2005 17:51 Edited at: 30th Jun 2005 18:02
Kelz,

For the paddle you have three options, which are, a sprite, an image(not bitmap, which differs from an image), or the 2D command box. You choose. But, might I say that a sprite will be the most efficient and wise choice.

A sprite has to be an image, and cannot be a bitmap. That is, unless the bitmap is copied to an image. However, this is still making the use of an image, not a bitmap. A bitmap is to edit and manipulate images behind the scenes(both commands are very useful in coilition). As where images, are to be paste to the screen, for the user to see.

By the way, from your description above, you are wanting to create a Breakout style game.

A menu will consist of a few objects, which includes the background of itself(being either an image or a sprite which is pasted or placed on the screen at specific coordinates), and then any objects that are on top of it that might change their position or appearance, due to the user's interaction or any other reason.


+NanoBrain+
pizzaman
22
Years of Service
User Offline
Joined: 18th Feb 2004
Location: Gateshead, UK
Posted: 2nd Jul 2005 05:21
In response to your original question of how to scroll a background click the following link

http://www.thegamecreators.com/?m=codebase_view&i=0ee878a92195ee8c39c59bc3196e47d1

This was some code I've posted frequently so its in the code base.

Also what NanoBrain said is very good info, however I just want to clear up, that an image can be an actual bitmap image file. From the post that one point isn't made too clear.

NanoBrain
21
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 2nd Jul 2005 10:46
pizzaman,

Thank you for clarifying my post. I did not catch this pit.


+NanoBrain+
Kelz
21
Years of Service
User Offline
Joined: 7th Apr 2005
Location: At the computer
Posted: 3rd Jul 2005 07:21
Okay so on a main menu, how, for example, would you make it so when you clicked on a button called 'instructions' it would take you to that screen?
NanoBrain
21
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 3rd Jul 2005 10:09 Edited at: 3rd Jul 2005 10:10
Kelz,

Well, there are several ways to do this, depending on the method which suits your coding style best. Let me first explain how you might go about splitting up your code, in general. I, personally, like to split up my source code into sections. These sections are groups of code, which are each wrapped into single if statements.

Example:


Notice each group of code wrapped in its own if statement. Each group of code will only run when its if statement is true, effectively splitting the source code into sections. Using this method, if you notice the name of the variable frmfocus meaning form focus, each section of code is a form. For example, form number 0 may be the main menu, form number 2 the options menu, form number 3 the section of code that is the game or gameplay.

Now that I have that out of the way, I can try to have you understand a way of pressing a button, that will switch forms.

If your button is an image, let's say a rectangle, the collision between it and the mouse is quite simple to detect. Let's now say that your button is 100 pixels wide and 50 pixels tall, and that its x and y coordinates are both placed at 0(the very top-left of the screen). To detect collision here, we need to compare the mouse coordinates to boundary coordinates of the rectangle. The left and right sides of the rectangle are both x coordinates, the bottom and top are both y coordinates. Therefore, this rectangle has a left coordinate of 0, right 100, top 0, bottom 50. Is this understandable? We are simply finding the coordinates of the left, top, right and bottom of the rectangle.

Onto collision. Simply put, if the mouse is past the left side of the rectangle(to the right of it), and is before the right side(to the left of it), and is past the top side(below it), and before the bottom side(above it), then the mouse is within the rectangle...collision.

Example:


If then, the mouse is within the rectangle, then a simple ifstatement can be used to detect mouse clicks, and by doing so, the form focus can be changed.

Example:


Ask, if you have any specific questions, or would like to know some more advanced tips, like changing the image of a sprite when the mouse collides with it etc.


+NanoBrain+
Kelz
21
Years of Service
User Offline
Joined: 7th Apr 2005
Location: At the computer
Posted: 3rd Jul 2005 17:51 Edited at: 3rd Jul 2005 17:52
Yup i understand that all completely.
Up until now i hadn't heard of that way of splitting code and it seems quite logical and simple.

The other two ways i know of is...
* Using functions (someone else explained these to me)
* using goto and gosub (also explained by someone but they said that code could become quite buggy and that functions were more practical)

From your point of view, NanoBrain, Do you think that splitting the code into if statements would be an easier more practical way for me to use or should i try to work with functions?
NanoBrain
21
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 4th Jul 2005 04:36 Edited at: 4th Jul 2005 04:44
Kelz,

Functions also are a very good way to split up a program. This is because you can split up your program into seperate #include files. This makes for much more neat tidy programs, easy to follow and update. Although, the form focus method is still needed to make this work correctly. Each function would be its own form, with its own local variables. The only variable needed to be returned would be frmfocus, so that the driver file of the program would know which function(s) to run. Also, frmfocus needs to be carried out through each function, in order for a correct value to be returned by each function.

Example:


I agree that goto and gosub commands are no good, except when used with data being held within your program, due to them giving you the ability to switch to a specific section of data easily. Functions are definitely the best way to go, like I stated, due to their tidiness. Also remember, that functions can be used within functions also. I would section my code into functions, controlled by the frmfocus variable. Any code that is going to be repeated multiple times throuout the program, place into a seperate function to be called. This will shorten your source code and make it easier to understand.


+NanoBrain+
Kelz
21
Years of Service
User Offline
Joined: 7th Apr 2005
Location: At the computer
Posted: 5th Jul 2005 07:45 Edited at: 5th Jul 2005 07:45
Well so far i have myself a basic background, a basic sprite for a paddle and i've managed to make the paddle move from one edge of the screen to another

For me thats quite an achievement hehe!

Then i thought i need a ball that will bounce off the paddle, the walls and the bricks (havent got these yet) and i am pretty sure artifical gravity needs to take an effect somewhere.
brain overload!

I could only start to think about what i need but have no idea how to implement it. Don't spose you could help me NanoBrain? anyone else who could offer help would be greatly appreciated
NanoBrain
21
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 5th Jul 2005 09:53
Kelz,

Let me first state that I am not a DBPro user, though I will be once I have the money to blow. For now, priorities. However, these methods you should be able to simply implement or convert to DBPro.

Let's start with the ball. Since you are wanting to create a Breakout style game, gravity is not necessary, just angles. If later, you wish to implement gravity, I will explain it to you. However, for now, let's leave it be.

To create the ball, make a simple image of a circle. For easy program sakes, make the image to be the same height as the width. Let's create a ball that has a dimameter of 20(diameter is the length across the circle, from one end to the other), so that the image needs to be a width and height of 20 pixels.

Above, I stated the need for the use of angles, which is a method of geometry and not physics. When I speak of this, I am saying that when the ball hits a brick or a paddle or a wall, its angle of direction needs to shift accordingly. Let's say that(looking at the screen in a 2D sense) if you throw a ball to the right, completely horizontal, it will be going at an angle of 90 degrees. When the ball hits the right wall(the right side of the computer screen), its angle will shift to 270 degress(left, completely horizontal). This is easy to compute in our heads. However, an angle of 72 degrees is a bit harder to understand.

Using sin as the balls x movement, and cos as its y movement, I will simply give you the formulas to compute the new angles, once the ball has hit various surfaces.

1. If ball's x position touches left or right side of screen, or left and right side of a brick or paddle, then subtract the ball's current angle(pre-impact angle) from 360. newangle = 360 - currentangle

2. If ball's y position touches top or bottom of screen, or top or bottom of a brick, then subtract the ball's current angle from 180, and increase the new angle by 360 if its value is below 0.
newangle = 180 - currentangle
if newangle is less than 0 then increase newangle by 360


....to be continued.


+NanoBrain+
Kelz
21
Years of Service
User Offline
Joined: 7th Apr 2005
Location: At the computer
Posted: 6th Jul 2005 17:50
This is quite weird...

NanoBrain,

I've seen that you've posted twice on the main home forum screen reccently, once yesterday afternoon and once early this morning (english time) but each time i click on the forum there is no new post here. On the 2d forum screen, it doesn't display the new post there either

Is this because there's an error or can other people see the post and it's just me who can't?
NanoBrain
21
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 6th Jul 2005 17:54 Edited at: 6th Jul 2005 17:56
Kelz,

Do you use your browser's back button within these forums often, or sometimes. This could be the problem.


+NanoBrain+
Kelz
21
Years of Service
User Offline
Joined: 7th Apr 2005
Location: At the computer
Posted: 6th Jul 2005 21:17 Edited at: 6th Jul 2005 21:19
ah that message shows.
I do use the back button but i refreshed several times and i tried looking at this same page on 2 different internet browsers (IE and Firefox) I also used two different computers and had the exact same problem
Kelz
21
Years of Service
User Offline
Joined: 7th Apr 2005
Location: At the computer
Posted: 9th Jul 2005 02:30
By the way the messages still haven't shown.
Please i still need help with this and i was wondering if anyone could assist me? (apart from NanoBrain (who has been helping))
Thank you
Kelz
21
Years of Service
User Offline
Joined: 7th Apr 2005
Location: At the computer
Posted: 9th Jul 2005 06:47 Edited at: 9th Jul 2005 07:23
I have got the ball to move around the screen it doesn't use sin or cos but it has the desired effect

Next problem. I've created my brick as a bmp, but how do i put them on the screen? Do i do it as a sprite? (as i need the ball to collide with each brick) then i have to make each brick dissapear when hit

Is there any help on this problem?

EDIT: although i got the ball moving i've realised a problem. The ball moves in a pattern and therefore is not much use, so i do still need help
D Ogre
22
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 9th Jul 2005 14:48 Edited at: 9th Jul 2005 14:50
Kelz,

The answer to your question about your bitmap is, yes, you could use a sprite and then check for collision. Just make sure you grab your bitmap as an image. You can either load it as an image or use the GET IMAGE (from a bitmap) command. Use the SET SPRITE SpriteNumber, Backsave state, Transparency and SPRITE [SpriteNumber, X, Y, ImageNumber commands to use your images as sprites.

If you are using DBPRO for your game, you don't have pixel perfect collision like DBC. This means if your image contains a lot of black (rgb 0,0,0) around the ball and paddle, the collision functions don't ignore those areas. The result will appear as if the sprites never touched when in reality they did.

If you need PPC, IanM posted a DBPRO function in the code base section for this. Just cut and paste it at the end of your program somewhere and use the function call for it instead of DBPRO's SPRITE HIT() and SPRITE COLLISION() functions. Make sure the transparency is set to 1 (on) for your sprites.

How are you currently calculating your movement for the ball? You might want to use SIN and COS to do this as NanBrain had mentioned. Let us see a code snippet first.
Kelz
21
Years of Service
User Offline
Joined: 7th Apr 2005
Location: At the computer
Posted: 10th Jul 2005 03:19
I don't have much clue as to how to use cos and sin in the movement of my ball. Here is the method i'm using at the moment and has a few problems


The main problem being sometimes the ball starts going back and forth across the screen without changing it's angle and also the balls movement is quite unrealistic

By the way i tried the PPC and i couldn't get it to work but i've solved the problem anyway. Thanks for helping.

Login to post a reply

Server time is: 2026-06-12 11:22:28
Your offset time is: 2026-06-12 11:22:28