PDA

View Full Version : Shooting Game By T Kill3r



CiNiMoDZA
16-10-2007, 10:17 PM
Just posting as I dont think he can create threads yet!!!

Original Quote:



Ok. Its on. The 'beam' i have there at the objects is just to test out the ammo thing.
(and please excuse how much the game sucks. its only my 1st real one)



Link: http://gamedev.openhazel.co.za/filecloset/download.php?id=248

Just re-name it to .gm6 once you've downloaded it!!!

CiNiMoDZA
16-10-2007, 10:24 PM
Well, if it means anything, its one hell of a lot better than the first game I made!!! (Hotel Manager :P )
There are better and easy ways of doing this game!!! Im not the best person to do it but what I'll do is edit the code and show you what I edited!!! Ill post comments so that you can see what I did and what its doing!! Otherwise, a very good game for a first game in my opinion!!! Hope to see some more releases!!!

P.S Did you make all you animations!!! (The cannon and little yellow robot thingy!?!)

T_Kill3r
17-10-2007, 03:34 PM
Thx alot man :D
and no. I didn't create every... but i did create most of it (trees, backround and missile. i was in a rush with the missiles. thats why they look like that)

well, i added a beam now, but not one comin from the cannon. I just got this big-ass beam that shoot from the side and moves up; buts its just temporary till i can make it from the cannon.
All help will be apprecreciated. thx

T_Kill3r
17-10-2007, 03:39 PM
I'm only in grade 9 and i am only starting programming. Thats why i have no codes. Thats why i just try to solve everytin with variables and all these other stuff. It might not be the easiest way, but its the only way i know it...

Tr00jg
17-10-2007, 11:29 PM
I'm only in grade 9 and i am only starting programming. Thats why i have no codes. Thats why i just try to solve everytin with variables and all these other stuff. It might not be the easiest way, but its the only way i know it...

That's where I started and that's where everyone started. The best was seeing how my style evolved with each game I made. Roach Toaster 1 was still made completely with drag and drop (in Game Maker). :)

CiNiMoDZA
18-10-2007, 12:47 PM
Its cool, as soon as you know whats going on with GML, you see its actually really easy, and logical. For example, to create an instance you just type instance_create() :P

dislekcia
18-10-2007, 04:47 PM
Right. About the beam-weapon logic thing...

I'm assuming you want a beam that "stops" when it hits a target, so not a straight line through everything. There are three ways that I've used over the years to get beam effects.

The first is simple: Split the beam up into lots of smaller objects. In the object's create event you make it spawn another object in the direction of the beam if the current instance isn't colliding with a target/obstacle. What this does is creates a "stream" of objects in a single frame (I'd suggest you make a maximum number of beam objects, otherwise you could hit an infinite loop) that all merge together to look like one solid beam. Code would look something like this:


//Fire the beam:
beamDirection = point_direction(x, y, mouse_x, mouse_y); //direction the beam will travel in
beamPartLength = 10; //the beam is split into objects that are each 10 pixels long...
beamCount = 0; //A counter for the parts of the beam so far...
beam_x = x;
beam_y = y;

while (beamCount < 60) {
part = instance_create(beam_x, beam_y, BeamPart); //create the beam part and keep a pointer to it so we can edit it
part.image_angle = beamDirection; //rotate the beam part so that it's pointing the right way...
with (part) {
//we use position_meeting() to see if the new part is colliding with an obstacle...
//if it is, we force the beam to stop by making beamCount too big for the loop to continue
if (position_meeting(x, y, Obstacle)) other.beamCount = 10000;
}

//move the next beam part along the path of the beam:
beam_x += lengthdir_x(beamPartLength, beamDirection);
beam_y += lengthdir_y(beamPartLength, beamDirection);
beamCount += 1;
}

The other two methods are a little more complex but more elegant, both rely on the idea of doing a binary search along the possible path of the beam to find out where the beam stops, once you know where that collision point is, you can easily draw an effect/line/sprite up to that point.

The second method uses collision_line() to test from the firing point to the maximum length of the beam, if it returns true for a collision then we split the length tested in two and test the first half - if that doesn't collide then we test the second half. Whichever part collides is then broken in two and tested again, until the lengths of the lines when broken in two is smaller than some minimum length, I tend to use 2 pixels. Eventually the halfway point when the line is too short to be worth testing is the point at which your beam should stop. Easy.

The third method uses the same logic as the second method, but instead of testing using collision_line, we test using a sprite that's origin is all the way to the left of the sprite, meaning that when we change the scale of the sprite it "grows" to the right. We start off with the sprite scaled to the maximum beam length (image_xscale = maxLength / sprite_width) and if it collides (using position_meeting), set the sprite to half that length and test again. If it collides we shorten it and try again, if it doesn't collide we lengthen it and retry, repeat until the shortening/lengthening distance is small enough to be accurate. The nice thing about this method is that it gives you the effect for the beam for free, so you don't have to draw it yourself, plus the beam is self-contained: You don't have to do any logic outside the beam object, you can just fire it and it'll sort itself out.

-D

T_Kill3r
18-10-2007, 07:28 PM
0.o

to much for my tiny brain to handle
I understand most of wats going on in the code, and i understand the 2nd method (but i wouldn't know how to do it)

Will the codes be simpler if the beam just blasts through everyting?

Tr00jg
18-10-2007, 10:00 PM
0.o

to much for my tiny brain to handle
I understand most of wats going on in the code, and i understand the 2nd method (but i wouldn't know how to do it)

Will the codes be simpler if the beam just blasts through everyting?

Only slightly. If you leave this part out (which then causes it to "blast" through everything):



with (part) {
//we use position_meeting() to see if the new part is colliding with an obstacle...
//if it is, we force the beam to stop by making beamCount too big for the loop to continue
if (position_meeting(x, y, Obstacle)) other.beamCount = 10000;
}


It will then go for BeamPartLength*60 pixels, ie in this case 600 pixels. :)

dislekcia
19-10-2007, 12:05 AM
Yes T_killer, it'll be a lot simpler to implement if you want the beam to go straight through everything: All you have to do is have a single long sprite for the beam with it's origin set to be all the way over on one side, then you simply rotate it to the correct direction and have the things that collide with it get damaged. Simple.

Shame on you Tr00jg, over complicating things! That code is only useful if you want a beam that stops when it hits things ;)

-D

Tr00jg
19-10-2007, 12:19 AM
Yes T_killer, it'll be a lot simpler to implement if you want the beam to go straight through everything: All you have to do is have a single long sprite for the beam with it's origin set to be all the way over on one side, then you simply rotate it to the correct direction and have the things that collide with it get damaged. Simple.

Shame on you Tr00jg, over complicating things! That code is only useful if you want a beam that stops when it hits things ;)

-D

Oh yeah d'oh. lol... Didn't see the obvious choice. >.<

T_Kill3r
21-10-2007, 12:24 PM
Yes T_killer, it'll be a lot simpler to implement if you want the beam to go straight through everything: All you have to do is have a single long sprite for the beam with it's origin set to be all the way over on one side, then you simply rotate it to the correct direction and have the things that collide with it get damaged. Simple.


-D


Yup. seems like the better otion for me :D

T_Kill3r
25-10-2007, 06:00 PM
Hey CiNiMoDZA, instead of me having all those missile creators spread out at the top of the room, will it be easier to just have one and then make the missile be create at y=-20 and x=random room width. And then to create multiple ones i just make more that one alarm.

would that work? will it be better?

dislekcia
25-10-2007, 11:26 PM
Hey CiNiMoDZA, instead of me having all those missile creators spread out at the top of the room, will it be easier to just have one and then make the missile be create at y=-20 and x=random room width. And then to create multiple ones i just make more that one alarm.

would that work? will it be better?

Yup, that'll work :)

-D

T_Kill3r
01-11-2007, 03:06 PM
Ok. I've been a bit busy with school lately so haven't been able to do anything with game yet, but i have some time today. So does anyone have an animation of a helicopter from the side?

T_Kill3r
02-11-2007, 05:54 PM
How do i give an enemy health? I want to put in a big missile that i have to shoot 5 times before it is destroyed. how do i do this?

*edit
Theres this really cool tune that i want for the game but its an 'IT' file and it cant run in GM. Is it possible for me to change the format or make it GM compatable?

Gazza_N
02-11-2007, 06:21 PM
How do i give an enemy health? I want to put in a big missile that i have to shoot 5 times before it is destroyed. how do i do this?

I would suggest having a 'health" or "hits" variable for your missile, and assign the number of hits you want it to take (5 in this case). Have your player's projectiles deduct one hit-point each time they impact the missile. Then just set the missile to kill itself when it runs out of hit points. If you need more detailed help in terms of implementation, just say the word. :)

As for the sound, IT isn't a format I'm familiar with... You'll have to find a sound editor or codecs that can do the conversion. Try googling it and seeing what you can find.

T_Kill3r
02-11-2007, 06:36 PM
I would suggest having a 'health" or "hits" variable for your missile, and assign the number of hits you want it to take (5 in this case). Have your player's projectiles deduct one hit-point each time they impact the missile. Then just set the missile to kill itself when it runs out of hit points. If you need more detailed help in terms of implementation, just say the word. :).


thx hey! I never thought of that