my little shooter game

BlitzMax Forums/BlitzMax Beginners Area/my little shooter game

B(Posted 2010) [#1]
hey guys

been working on using types and methods and decided to try and use bullets, which
have, until now alluded me.

here is my first attempt, which turned into a little mini game.



tell me what you think

ps made this in 2 days so its all just thrown together.

controls arrow keys to move and space to shoot
shift to slow down


Czar Flavius(Posted 2010) [#2]
Wow that's pretty cool! I like the use of text as enemies. What is the giant If statement chain at the beginning of the While loop for?


B(Posted 2010) [#3]
just a quick a dirty way to get done what i wanted, im chaning it later when I have time.

on another note:
i tried to use as little for nexts as possible due to how much it slows down the game.

i wanna change it into a real game with sound and actual graphics.

altho i am, as always, a HUGE fan of ascii art


Czar Flavius(Posted 2010) [#4]
How for for nexts slow down the game? What did you replace them with?


B(Posted 2010) [#5]
I put an if statement in the main loop.

pseudo code
if e[enemies%] < enemymax%

do stuff

enemies:+1
endif


e[] is my bullet array type and enemies% and enemymax% are global int vars

so it increases every loop instead of increasing all of the enemies every loop
i only do 1 every loop, i dont know that it speeds up the game alot but it works.

i have a tendancy to use for next loops way too much and it slows down my games.


is there a better way?


Jesse(Posted 2010) [#6]
do you know that this:
If plyr.level% = 1
	plyr.move()
	plyr.shooting()
	e[1].show()
	e[1].move()
	outline()
	stuff()
Else If plyr.level% = 2
	plyr.move()
	plyr.shooting()
	e[1].show()
	e[1].move()
	outline()
	stuff()
Else If plyr.level% = 3
	plyr.move()
	plyr.shooting()
	e[1].show()
	e[1].move()
	outline()
	stuff()
Else If plyr.level% = 4
	plyr.move()
	plyr.shooting()
	e[1].show()
	e[1].move()
	outline()
	stuff()
Else If plyr.level% = 5
	plyr.move()
	plyr.shooting()
	e[1].show()
	e[1].move()
	outline()
	stuff()
Else If plyr.level% = 6
	plyr.move()
	plyr.shooting()
	e[1].show()
	e[1].move()
	outline()
	stuff()
Else If plyr.level% = 7
	plyr.move()
	plyr.shooting()
	e[1].show()
	e[1].move()
	outline()
	stuff()
Else If plyr.level% = 8
	plyr.move()
	plyr.shooting()
	e[1].show()
	e[1].move()
	outline()
	stuff()
Else If plyr.level% = 9
	plyr.move()
	plyr.shooting()
	e[1].show()
	e[1].move()
	outline()
	stuff()
Else If plyr.level% = 10
	plyr.move()
	plyr.shooting()
	e[1].show()
	e[1].move()
	outline()
	stuff()
Else If plyr.level% = 11
	plyr.move()
	plyr.shooting()
	e[1].show()
	e[1].move()
	outline()
	stuff()
Else If plyr.level% = 12
	plyr.move()
	plyr.shooting()
	e[1].show()
	e[1].move()
	outline()
	stuff()
Else
SetScale(2,2)
DrawText "YOU WIN!",350,230
SetScale(1,1)
toggle% = 1
stuff()
EndIf

could have been done like this:
If plyr.level% <= 12   'or < 13
	plyr.move()
	plyr.shooting()
	e[1].show()
	e[1].move()
	outline()
	stuff()
Else
 SetScale(2,2)
 DrawText "YOU WIN!",350,230
 SetScale(1,1)
 toggle% = 1
 stuff()
EndIf



Czar Flavius(Posted 2010) [#7]
if e[enemies%] < enemymax%

do stuff

enemies:+1
endif


Is the exact same as

for local i:int = 0 until e.Length

do stuff

next



B(Posted 2010) [#8]
@ Jesse
ya i know but i didnt want to think about it
i know it couldve been done faster
i didnt ask for how to do that easier

@ Czar
but doesnt that do all that is in:
for local i:int = 0 until e.Length

do stuff

next


all at once in the loop then it would halt the program and do all that then continue the rest?

im am under the impression that mine does not do that but if my code does that then i will do it using for nexts instead


Czar Flavius(Posted 2010) [#9]
Oops I apologize I misread your original code. I don't understand what it is meant to do.


Jesse(Posted 2010) [#10]

tell me what you think


that seemed pretty general to me.

and I thought I was helping. Oh well.


B(Posted 2010) [#11]
sorry guys i had bad day of people yelling at me all day and felt like you guys were too.

sorry.

@jesse
you were helping, but at the time i was more concerned with what czar and i were
talking about.
do you understand what i am trying to say? im not sure if i am wording it correctly or not.

@czar
it does the same as your code.
however i am under the impression that using the for next method the program will read
the code from the top of the while loop to the wend, and upon reaching a for next it will
stay at the for next untill it is satisfied and then move on. and my understanding is that if
i use a for next and have a large variable that it needs to satisfy it will slow the program down as it tries to complete it.
my method using an if statement, i think–albeit not entirely sure–that it will simply do it once per loop instead of the total number every loop.

say i had 100 bad guys and using the for next it increase their y coords by 1 100 times every loop, i want to increase 1 bad guys every loop so it will run faster.

am i mistaken with this idea that i have?


jondecker76(Posted 2010) [#12]
B
I understand your idea - you want to spread the load of updating y coords over a period of time, instead of doing it each loop. The method you have does work, though I doubt updating all of them every iteration would really slow anything down at all. The game is very simple and you have many many spare cpu cycles to use. There is nothing wrong with optimization, but you may find that you don't even need it. Thats why most people code everything first, then optimize only if necessary.

Another method to do the type of optimization that you wanted to do would be to let your enemy Type handle it. Give it a new field: update_frequency:int, then in your move() method, do some simple math to decide when to update their position. IMO, it would be a cleaner approach.

But again, I think you are overthinking it a bit, and there is no need for the optimization...


Czar Flavius(Posted 2010) [#13]
Here's how to test speed of your code
Strict
Local start = MilliSecs()
Local e[100000]

For Local i = 0 Until e.length
	e[i] :+ 1
Next

Print "It took " + String(MilliSecs() - start) + " milliseconds to iterate through " + e.length + " items."


On my computer (2.4Ghz quadcore) with debug mode off:

It took 1 milliseconds to iterate through 100000 items.


Do not worry about this :)


B(Posted 2010) [#14]
@ JonD
Thanks. i guess i was over thinking it a bit too much. I just had problems with a program
i made recently and it was really slow and im pretty sure it was due to the for next
within a for next. so that made me super paranoid. haha. thanks for the help.
ill integrate your idea. :)

@ Czar
OK i was freaking out about nothing. haha.
i have a 2.4Ghz Intel Core 2 Duo so i think it will be fine on mine as well.