Space If Evaders

Post here your demos and examples with the source files.
Forum rules
Always post the games with a screenshot.
The file must have the ged and data files (complete game source)
Use the forum attachment to post the files.
It is always better to use the first post to put the game files

Space If Evaders

Postby foleyjo » Wed Jan 18, 2012 6:53 pm

Hi all

Just a small little project I set myself. I have tried to make a space invaders game without using the word If in the code. (The game title doesn't count)

I have cheated on 1 or 2 steps and used a switch case statement but this was when I couldn't find an alternative.

So an example would be an actor that has 3 hit points and when they run out it's destroyed. I did not know an alternative to

Code: Select all
if(hp <=0)
  destroyactor;


other than
Code: Select all
switch(hp)
{
case 0: destroyactor; break;
}



****UPDATE - Changed the switch case statements to use a for loop like in SuperSonics example. Also fixed some tiny bugs that I found. BOY I HATE THOSE BUGS :x
Attachments
IFINV.zip
(968.86 KiB) Downloaded 177 times
Ifinv.png
Ifinv.png (34.67 KiB) Viewed 3575 times
Last edited by foleyjo on Thu Jan 19, 2012 9:07 am, edited 1 time in total.
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Re: Space If Evaders

Postby SuperSonic » Wed Jan 18, 2012 7:56 pm

Try making an int in global code like this:
Code: Select all
int i;

Then on your actor's draw code, put this:
Code: Select all
for(i = hp; i < 1; i++)
{
    destroyactor;
}

:D
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: Space If Evaders

Postby Jagmaster » Wed Jan 18, 2012 8:39 pm

That's a good solution SS. :o
User avatar
Jagmaster
 
Posts: 875
Joined: Sun May 08, 2011 4:14 pm
Location: Not where you think.
Score: 82 Give a positive score

Re: Space If Evaders

Postby SuperSonic » Wed Jan 18, 2012 8:56 pm

Thanks^^
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: Space If Evaders

Postby foleyjo » Wed Jan 18, 2012 9:31 pm

I like it :D

I will make the changes when I get the chance
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Re: Space If Evaders

Postby Game A Gogo » Wed Jan 18, 2012 11:35 pm

You should realized that just because you're not using the word's "if" in your script does not mean you're doing anything better.

it's not the if that takes a lot of computing but the condition check and there's usually no way to avoid this!

Using a for loop or a switch case is actually a worst practice than using if, as they all do a condition check, but the for and switch try to do more than it should!
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: Space If Evaders

Postby Fojam » Thu Jan 19, 2012 12:00 am

i thought switch was more efficient than if?
CLICK TO GIVE ME POINTS

My Latest Projects:
Super Smash Bros: viewtopic.php?f=6&t=12307 PLEASE help by making sprites!
User avatar
Fojam
 
Posts: 513
Joined: Thu Mar 19, 2009 10:02 pm
Location: under your bed!!!
Score: 69 Give a positive score

Re: Space If Evaders

Postby Game A Gogo » Thu Jan 19, 2012 2:45 am

Not if you're just checking for one state
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: Space If Evaders

Postby foleyjo » Thu Jan 19, 2012 8:00 am

I would have thought the for loop SS exampled would be just as efficient because the for loop would be ignored until the condition was true.

Don't worry GAG I didn't think this was the best solution for a space invaders game :lol: . I know exactly where to put the if's to make everything better.
The reason I did this was due to something I read in one of the If Haters threads. I can't remember who said it but they said while at college their teacher gave them a project to rewrite some code without using if's .
I thought that would be a nice challenge to test what I have learned so far.
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Re: Space If Evaders

Postby SuperSonic » Thu Jan 19, 2012 4:57 pm

foleyjo wrote:I like it :D

I will make the changes when I get the chance

Awsome. Glad I could help :P
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: Space If Evaders

Postby tintran » Thu Jan 19, 2012 7:37 pm

nice remake!
User avatar
tintran
 
Posts: 157
Joined: Fri Dec 24, 2010 1:34 am
Score: 30 Give a positive score


Return to Game Demos

Who is online

Users browsing this forum: No registered users and 1 guest

cron