News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

My second game: Hell Eagle

Started by Sigtrygg, July 05, 2012, 01:54:17 PM

Previous topic - Next topic

kevin

#15
QuoteI try to optimize the source code for the game "Hell Eagle" considering
your hints and then I will post the code again. But it could take some
time...

 Looking over the program again (briefly), I think the biggest opportunity for improvement can could found in the rescue() function.  It seems like that for each man character there's custom section code to drive it's action.   The function is about 600 lines of code long, we're we could probably reduce it to less than 100 by simply using a state machine and for/next loop to process the men characters.

 A State Machine is just what name implies, our characters have various states and we can change their behavior by changing the state. The update functions selects what control code to use for each character via it's state field.  Generally via SELECT CASE statement.   The little men characters could have say 2 or 3 different states.   Which might be 1) Standing (to be rescued), 2) Walking/Running to Chopper and  3) Rescued.    


  Here's the layout of the concept (not working code)

PlayBASIC Code: [Select]
  ; define our states for the various possible states
Constant PeopleState_Waiting =1
Constant PeopleState_Running =2
Constant PeopleState_Rescued =3

Type people
State

x_pos#
y_pos#
xto_pos#
yto_pos#
speed
Anim_men
FrameSheet
EndType

Dim men(40) As people




; -----------------------------------------------------------------------------------------------
; Here's a mock up of how the processing function to control the MEN characters could look like
; -----------------------------------------------------------------------------------------------


Function ProcessMen()


For lp =0 to 40

; check if a man exists at this position within the array
if Men(lp)


; Select what STATE this men is in
Select men(lp).State

; -------------------------------------
case PeopleState_Waiting
; -------------------------------------

; Code goes here to animate/render the standing dude



; -------------------------------------
case PeopleState_Running
; -------------------------------------


; Check what side of the player the man is on
if men(lp).X < PLayer.X
; men to the left of player, so move right

; also check if the men hits the pick up point,
; if so, set the man's state to PeopleState_Rescued

else

; men to the left of player, so move right

; also check if the men hits the pick up point,
; if so, set the man's state to PeopleState_Rescued

endif



; -------------------------------------
case PeopleState_Rescued
; -------------------------------------

; Do nothing, already picked this dude up.
; Here you can actually delete this man from
; the array (and any animations he's used)




EndSelect

endif

next

EndFunction





   We can further expand this to create conceptual links between the MEN characters and the PLATFORMS.   The simplest way would be to create type for our Platforms and use an array to hold them all within the one structure, just like the men.    To create our links,  we add a field to the PEOPLE type, this field would hold the index of the platform this man responds to.  So when the Player lands on platform SIX say, this platform sets it's player status to TRUE.    Inside the   ProcessMen() each man is checking it's linked platforms status to set it's mode.    So if the playing is sitting on the platform, then the character is set to  PeopleState_Running, if the player isn't sitting on the platform it's set to standing.    


     Again here's some more mock up code of the type of solution.  

PlayBASIC Code: [Select]
  ; define our states for the various possible states
Constant PeopleState_Waiting =1
Constant PeopleState_Running =2
Constant PeopleState_Rescued =3



Type tPlatform
; is the player sitting on this platform ?
PlayerLandedStatus

; Position in world
x#,y#

; Size
Width,Height

EndType

Dim PLatform(100) as tPlatform




Type people
State
PLatformIndex

x_pos#
y_pos#
xto_pos#
yto_pos#
speed
Anim_men
FrameSheet
EndType

Dim men(40) As people





Function ProcessPLatforms()

; This function runs through the platforms and check if they hit\
; the players sprite.

For lp =0 to 100

; check if a platforms exists at this position within the array
if PLatform(lp)

; check if platform rect hits the player sprite
x1=PLatform(lp).x
y1=PLatform(lp).y
x2=x1+PLatform(lp).Width
y2=y1+PLatform(lp).Height

State=False
if RectHitSpritePixels(x1,y1,x2,y2,Player.Sprite,1)
State=True
Endif


; here you could check if the rotation of the player to make sure
; they're level enough to make a safe landing also

; anyway, here we just set the
PLatform(lp).PlayerLandedStatus=State

endif
next


EndFunction

; -----------------------------------------------------------------------------------------------
; Here's a mock up of how the processing function to control the MEN characters could look like
; -----------------------------------------------------------------------------------------------


Function ProcessMen()


For lp =0 to 40

; check if a man exists at this position within the array
if Men(lp)


; Get the landing platform this man is linked to

MyLandingPlatform=Men(lp).PLatformIndex






; Select what STATE this men is in
Select men(lp).State

; -------------------------------------
case PeopleState_Waiting
; -------------------------------------

; Code goes here to animate/render the standing dude


; check if the player is sitting on this platform
; if they are, swap to running mode
if PLatform(MyLandingPlatform).PlayerLandedStatus = true
men(lp).State=PeopleState_Running
endif



; -------------------------------------
case PeopleState_Running
; -------------------------------------


; check if the player is NOT sitting on this platform
; if they aren't, then set it back to standing
if PLatform(MyLandingPlatform).PlayerLandedStatus = true
men(lp).State=PeopleState_Waiting
endif



; Check what side of the player the man is on
if men(lp).X < PLayer.X
; men to the left of player, so move right

; also check if the men hits the pick up point,
; if so, set the man's state to PeopleState_Rescued

else

; men to the left of player, so move right

; also check if the men hits the pick up point,
; if so, set the man's state to PeopleState_Rescued

endif

Login required to view complete source code



  The benefits are too many to list really, apart from being less code, we're simply making our program easier to change without fear of variable collisions and logic errors.  But really one of the best advantages is that we can externalize hard coded DATA from the CODE.  Allowing you create multiple levels easily.



 

BlinkOk

hey Sigtrygg dude,
this is a really great game mate. i have played it quite a few times.
i was wondering if you would be interested in re skinning it.
there wouldn't be many changes and i don't think it would take up too much of your time.
anyway. just a suggestion.
let me know ok?

Sigtrygg

Hello BlinkOK!

Do you think to give the game an other look?
Of course, I am interested in.
What is your idea?
At the time I make the game a litle bit larger and
I try to apply some of the hints from Kevin.
When I have finished I will post the game again
together with sourcecode.

Greetings from Sigtrygg

BlinkOk

ok no worries mate. i'll put something together. it's either a space taxi thingy or an alien space ship and cows at the moment.

BlinkOk

#19
ok. here's my take on it (right click and view image to see full size);


in a post apocalyptic world gone mad...
where cities are suspended in the air by massive girders and cars fly...
chicks in tight little red skirts still manage to get out on a Saturday night!
it is your job to get them home Sunday morning....you are bob the taxi guy!


you gotta get the chicks home. you have to manage fuel and stay away from the rocks/girders.
we could have spikes and stuff that pops up and smashes you and cops that patrol here and there.
we could have power ups like faster speed and invincibility
the more chicks in the car the slower you go and the more fuel you use.

this may take me a little while to get together though. maybe a week
let me know what you think

kevin


are you going make it multiple (parallax styled) layers  ? 

micky4fun

Hi all

This looks very stunning indeed , looking forward to this one ,
Quoteare you going make it multiple (parallax styled) layers  ? 
looks the way to go

great stuff
mick :)

BlinkOk

Quoteare you going make it multiple (parallax styled) layers  ? 
if it's ok with sigtrygg dude then it's definitely a go.

ATLUS


monkeybot

Blink! your graphics are really rather excellent.

Sigtrygg

Hello BlinkOK!

Your graphics look fantastic!!  :o
In a few days (maybe Monday) I am going to publish a
new version of Hell Eagle. I have apply some hints of Kevin and
made the world larger and I integrated a better highscore-List
with 15 positions. I also made a choice of screen resolution, so
it is possible to run the game on laptops with 1600x900 resolution.
It's pitty that I didn't get an advantage by applying tha map-
function. I tried it, but I didn't get an advantage in speed, but
I have great problems with my sprite-collisions, so I didn't try it
further.
I think the computer today are so fast that it is no problem to
run the game rather somoothly.
Your idea with fuel consumption is good and I thougt of it too!
When I publish the new version of Hell Eagle I do it again with
all media files, so it would be great, if you can change it with your
cool graphics. I would be very appreciate, if we could work
together and make a nice looking game that makes fun! But, if you
want to change it of your own, you are welcome of course.
I don't want the game for me! You all of the community can
change code and media of your own, and can use it how you want!
But of course it would be nice, if you would share your ideas with
us all. It is very exiting, what game we can create.

Greetings,

Sigtrygg

Sigtrygg

Hello Community!

Here is now Hell Eagle Version 1.2!
I made:
- a better highscoretable
- different screen-resolutions
- larger world
- a special enemy
and also I applied some hints of Kevin for the game.

You can download with source code and media-files:
http://rghost.net/39898639

Have much fun!
I am courious of BlinkOk new graphics for the game.

Greetings

Sigtrygg

BlinkOk

looks cool Sigtrygg dude. well done. it's a very
engaging game and has me on the edge of my seat when i play it.

you might have one problem with my graphics where you will
need (at least) three HUGH images to make the game.
1. sky/distant background
2. background
3. foreground
i'm not sure but i'm thinking that might be a little too much for some pcs.
maybe a system where you can build up a scene with smaller pieces of
graphics displaying only what the player can see at that moment

stevmjon

thanks for sharing your game sigtrygg.

hey blinkok, you come up with good graphics so quickly. you da man. you are very creative.

stevmjon
It's easy to start a program, but harder to finish it...

I think that means i am getting old and get side tracked too easy.

micky4fun

Hi All




Quotei'm not sure but i'm thinking that might be a little too much for some pcs.
maybe a system where you can build up a scene with smaller pieces of
graphics displaying only what the player can see at that moment

dont know if this might help as i had a simular problem with my airbourne game and Kevin came up with this ,
but i must amit i could not grasp it , but thats my small brain , lol

http://www.underwaredesign.com/forums/index.php?topic=2824.0

but i must admit its a very addictive game and with BlinkOk gfx's would be a must play
anyway good luck with this one

mick :)