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.

DarkBASIC Discussion / can someone check my code?

Author
Message
DarkComplicated wtf
9
Years of Service
User Offline
Joined: 6th Oct 2010
Location: NARNIAAAA!!!!!!
Posted: 13th Nov 2010 02:50
alright so for my second video game design project im making a fps alien/zombie killer and im trying to get airstrikes into my game and i think i came up with a code that may work can someone check it and tell me weather or not it seems reasonably plausable?[VIDEO GAME DESIGN
AIRSTRIKE CODE
airstrikes-
airstrikes=60/sync *REM 1 strike per minute
if inkey$ "5" = 1 then
if airstrike=0 then
load object "models/fighter.x",200
scale object 200,5000,5000,5000
position object 200, 5000,500,5000 *REM planes start out small so large scale factor
create object collision box 200,-2500,-2500,-2500,2500,2500,2500,0
set object collision on 200
load object "models/bombshells.x",300
scale object 300,250,250,250]

I'll make Halo look like poke'mon!

Attachments

Login to view attachments
DarkComplicated wtf
9
Years of Service
User Offline
Joined: 6th Oct 2010
Location: NARNIAAAA!!!!!!
Posted: 13th Nov 2010 02:51
thats not the entire thing thats in my post here it is i think

VIDEO GAME DESIGN
AIRSTRIKE CODE
airstrikes-
airstrikes=60/sync *REM 1 strike per minute
if inkey$ "5" = 1 then
if airstrike=0 then
load object "models/fighter.x",200
scale object 200,5000,5000,5000
position object 200, 5000,500,5000 *REM planes start out small so large scale factor
create object collision box 200,-2500,-2500,-2500,2500,2500,2500,0
set object collision on 200
load object "models/bombshells.x",300
scale object 300,250,250,250
create object collision box 300,-125,-125,-125,125,125,125,0
set object collision on 300
Position object 300,x,y,z *REM not yet sure on placement values
hide object 300
loop move object 200,150
load object "models/explosion.3ds",400
scale object 300,100,100,100
create object collision box -50,-50,-50,50,50,50,0
set object collision off 400
position object 400 x,y,z *REM not sure about positioning yet, may be random
hide object 400
if object collision (200,300)>0 then
show object 400
loop object 400,1,23
set object collision on 400
delete object 200
delete object 300
delete object 400
airstrike = 60/sync *REM restart airstrike support countdown
end if

I'll make Halo look like poke'mon!
SH4773R
10
Years of Service
User Offline
Joined: 18th Jan 2010
Location: AMERICA!!!
Posted: 13th Nov 2010 04:53
You should load all your models before the loop
DarkComplicated wtf
9
Years of Service
User Offline
Joined: 6th Oct 2010
Location: NARNIAAAA!!!!!!
Posted: 13th Nov 2010 05:01
well they are being deleted at the end of the loop to keep gameplay up to speed

I'll make Halo look like poke'mon!
SH4773R
10
Years of Service
User Offline
Joined: 18th Jan 2010
Location: AMERICA!!!
Posted: 13th Nov 2010 05:39
But it has to reload them each loop, so slower
Eminent
10
Years of Service
User Offline
Joined: 15th Jul 2010
Location:
Posted: 13th Nov 2010 06:13
Deleting objects is slow as hell so don't.


SH4773R
10
Years of Service
User Offline
Joined: 18th Jan 2010
Location: AMERICA!!!
Posted: 13th Nov 2010 06:41
Exactly my point.
Libervurto
14
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 13th Nov 2010 17:45 Edited at: 13th Nov 2010 17:46
First of all, to put your code in a snippet box type this:
{code}your code{/code} with square brackets instead of curly ones.

There are quite a few really basic errors in your code. For example you write "end if" instead of "endif". "loop move object" most commands cannot be looped like this, only animation and sound commands, for everything else you will have to make a loop and put the command inside the loop to repeat the command. Like this:


Quote: "airstrikes=60/sync *REM 1 strike per minute"

Sync is a command, it doesn't return a value so you can't use it to assign a variable. All commands that return a value in DB end with parentheses "()", for example inkey$() returns the string of the key currently being pressed.

Here is your code that I've cleaned up. It still doesn't work yet, I've just changed the structure and removed dead code. I've removed the collision detection stuff and we will use the bomb's height to decide when to detonate.

The first thing I've done is added a subroutine called "get_objects". Subroutines are blocks of code that are kept outside of the main program; everything between the label "get_objects:" and the RETURN statement is part of the get_objects subroutine and will be executed when we call the subroutine by typing "gosub get_objects".
Subroutines are mainly used to store processes that we want to use many times in the program, storing the process in a subroutine means we can simply call it to execute the code and we don't have to keep writing the same code over and over again.
In the case of "get_objects" we are just using a subroutine to tidy up our code.

The other thing I did was to add a DO loop. This is the most basic loop; when the program reads the command LOOP it jumps back up to DO and runs through the code again. If you want to leave the DO loop you can type EXIT - EXIT will leave any kind of loop.

I put an END after the main loop because, although I can't see any reason why the program would leave the main loop, it is best to be safe and end the program if it does to avoid it running into code that it's not supposed to.

I think you would really benefit from going through TDK's tutorials (stickied at the top of this board). They will give you a solid grounding on all the basic commands and how to write programs effectively.


Let's try and get your program working. We will fix it and turn it into a fun bombing game!

From what I understand you want the bomber to fly constantly forwards and drop a bomb when a key is pressed - but we are only allowed one bomb per minute. The bomb needs to explode on impact.

So what do we need to do? Here's our program in pseudo code - that means code that isn't real code but is useful for thinking through what we need to do.


Where do we start?
First we make all the independent things; if something doesn't rely on anything else to work we can make it straight away.
The independent code is everything outside of IF statements; here we have three things: moving the bomber, updating the airstrike timer and checking the fire key.
We'll leave moving the bomber for later because it requires a 3D model; 3D brings up complications that we don't need to tackle yet, and if we were making our own models for a game we don't want to have to halt coding to make models - especially if you are working with other people!
Reseting the airstrike timer relies on checking the fire key, so we'll write the fire key check first.

We're going to use spacekey() to fire.

You see how I omitted "=1", that's because IF checks for =1 by default.
This code will work fine because although it repeats firing, we will be limited by the airstrike timer.

Now let's make the Airstrike timer.
Only being allowed one bomb a minute is going to make testing slow, so I'll increase it to one bomb every three seconds while we're in the testing phase.
To make the timer we use timer(), which return the time the cpu clock has been running for in milliseconds - so 3000ms = 3s.

Now we can only fire once every three seconds. There are two problems with this code; there is nothing to tell the player when he can fire and the player can simply hold down spacekey to fire every time a bomb is available - we don't want our players to be so lazy!

To make our player press the key every time to release a bomb we need a switch.

Now we can only fire when spacekey has been pressed and it wasn't being held down the last time we checked.
To show the player when a bomb is ready we'll use a simple text message.

I had to change the way the display works because the bomb status needs to be constantly updated and if we didn't clear the screen it would write over itself and get messy.

If I have time I will come back and finish this.
The plan for the game is to have random targets appear on the ground and you have to time the release of the bomb accurately to get a strike.


Do oranges know what colour they are?
Latch
14
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 13th Nov 2010 17:47 Edited at: 13th Nov 2010 17:48
@DC

Obese beat me to the code box thing!

Enjoy your day.
DarkComplicated wtf
9
Years of Service
User Offline
Joined: 6th Oct 2010
Location: NARNIAAAA!!!!!!
Posted: 13th Nov 2010 18:50
holy crap obese thanks alot =)
this is my second game so im not that shocked my code will end up so differently lol i actually tried to make a code that will get you in and out of a jeep and it actually works except that when i get out it puts me in my spawn lol i basically just tried to take the things that worked from that code and adapt it into the airstrike.
and i'd love to see if you can finish up the code for the strike. also i have a crap load of other codes i gotta figure out like shooting and reloading which will also require alot of thinking, and i usually cant think of simple things, but then again it seems game coding cant be simple lol

I'll make Halo look like poke'mon!
Libervurto
14
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 13th Nov 2010 21:01
Okay, let's go back to our pseudo code and mark off what we've done.

We need to do all the bomber and bomb stuff now so we'll start using 3D. So that anyone can run my code, I'm going to use a simple cuboid to represent the bomber and a sphere to represent the bomb. These are called placeholders, using placehlders allows you to get on and make the game before substituting the placeholders for more detailed models later; we might find that the model we were intending to use isn't suitable for our game for some reason, and if we were making our own models we'd have wasted a lot of time modelling something that we can't use. Also if you are working in a team, placeholders let one person get on with the code while another is making the models.

I don't have DB running at the moment so I am having to imagine how this will look - you might have to adjust some of the values.
First let's make the bomber.


Hopefully that looks something like an aeroplane. Now let's try dropping a bomb.



Do oranges know what colour they are?
DarkComplicated wtf
9
Years of Service
User Offline
Joined: 6th Oct 2010
Location: NARNIAAAA!!!!!!
Posted: 13th Nov 2010 21:16
thank you, will the acceleration work by itself or will i need like a gravity code?

I'll make Halo look like poke'mon!
Libervurto
14
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 13th Nov 2010 22:22
The bombs only move down so we don't need a gravity effect.


Do oranges know what colour they are?
DarkComplicated wtf
9
Years of Service
User Offline
Joined: 6th Oct 2010
Location: NARNIAAAA!!!!!!
Posted: 14th Nov 2010 19:00
ok thx

I'll make Halo look like poke'mon!
DarkComplicated wtf
9
Years of Service
User Offline
Joined: 6th Oct 2010
Location: NARNIAAAA!!!!!!
Posted: 15th Nov 2010 00:32
hey now that i think of it theres 1 thing i definately need help on. i need to know if theres a command to check for enemies, because my game is just a 3 wave game and i need the program to check for enemies so once they are all gone it will spawn more and add a 1 to the wave number

I'll make Halo look like poke'mon!
Libervurto
14
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 15th Nov 2010 15:02
Use a variable to keep track of the number of enemies left and when one gets killed you subtract one from the variable. When it equals zero you know you've killed all the enemies.


Do oranges know what colour they are?
DarkComplicated wtf
9
Years of Service
User Offline
Joined: 6th Oct 2010
Location: NARNIAAAA!!!!!!
Posted: 16th Nov 2010 02:03
the airstrike code isnt working for me
im just moving on and tackleing that for later. what im worried about right now is a problem im getting with runtime error whenever i try to append object animation



i dont have any append attempts in there because i got so frustrated i deleted the attempt and decided to ask for help
hopefully my code snippet box is working this time and if not then i apologize but i just need to know where i would append the animation in the code, where im loading it or where i am doing the actual collision

I'll make Halo look like poke'mon!

Attachments

Login to view attachments
Libervurto
14
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 16th Nov 2010 10:50
for 21 = 1 to zombie
This should be
for zombie = 1 to 21

DB is weird so it will actually overwrite the value of 21 if you get this the wrong way around. As you can guess, overwriting numbers causes all kinds of problems.

Have you read TDK's tutorials yet?


Do oranges know what colour they are?
TheComet
12
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 17th Nov 2010 16:10 Edited at: 17th Nov 2010 16:11
And here's an example of what can go wrong when it overwrites a number:



TheComet

DarkComplicated wtf
9
Years of Service
User Offline
Joined: 6th Oct 2010
Location: NARNIAAAA!!!!!!
Posted: 18th Nov 2010 23:03
im not entirely sure if that answers my question how would i append animation to the models when i hit them?? i keep getting runtime and the message just says cannot append object animation or something like that

I'll make Halo look like poke'mon!
DarkComplicated wtf
9
Years of Service
User Offline
Joined: 6th Oct 2010
Location: NARNIAAAA!!!!!!
Posted: 18th Nov 2010 23:06
thank you though i will change it also i cant get first person to work on my character either

I'll make Halo look like poke'mon!
DarkComplicated wtf
9
Years of Service
User Offline
Joined: 6th Oct 2010
Location: NARNIAAAA!!!!!!
Posted: 18th Nov 2010 23:18
hey heres a link to my game in midprogress can you give me any suggestions? if you need to see the code ask for it and i'll link it to you
http://www.mediafire.com/?ksy2s5obshznpq9

I'll make Halo look like poke'mon!

Login to post a reply

Server time is: 2020-08-06 08:17:22
Your offset time is: 2020-08-06 08:17:22