Jump to content

Photo

Using sprites for platforms in a platform game


8 replies to this topic

#1 Retrospect OFFLINE  

Retrospect

    Stargunner

  • 1,102 posts
  • Location:Wakefield, England

Posted Fri Aug 17, 2018 6:36 AM

Hello everyone.

 

I've been itching to get another game created, this time a kind of platform game, rather like Eric in Monsterland but where the player doesn't just stay on one level.

 

I've been having a look at games like Wonderboy for various computers, and I saw something rather interesting .... The "platforms" were flickering.  This can mean only one thing  - the coders actually used sprites for the platform rather than graphical characters, which would make sense.

 

So I thought to myself, Well I can do this.  Then I thought deeper into it and thought; if I do use a sprite as a platform, what's to stop the player character simply hitting that platform sprite, with say his head, and inadvertently moving onto that platform?  So what do we do, do we have some sort of CALL COINC command that detects only the bottom of the player, or do I have the player's feet as a separate sprite?

 

Any ideas would be great because even though I've been shown examples using graphical characters for platforms by people including Tursi's example, I've struggled.  I want to make another game but it can't simply be another one-level platformer again.



#2 Retrospect OFFLINE  

Retrospect

    Stargunner

  • Topic Starter
  • 1,102 posts
  • Location:Wakefield, England

Posted Fri Aug 17, 2018 7:11 AM

I've come up with some example code in Extended Basic.

 

The problem I have, is really two things. 

 

The platform is there as a sprite, and the player can only really get onto the platform if they are directly under the middle of it.

 

Once on the platform, how do I get it so that the player can simply drop-off the platform again and assume position on the ground?

 

Copy & paste this example into either Classic99 or JS99er using XB.

 

! -----------------------------------------------------------------------------------------------------------

 

! SIMPLE PLATFORM EXAMPLE IN EXTENDED BASIC
 
! VARIABLES:
 
! MAN = Player character number, for example 100 to 112 are player patterns for animation
! MX = Player's X position
! MY = Player's Y position
 
 
1 CALL CHAR(100,"030307030303010307070F0F03070607C0C0E040E0C080C0E0E0F0F0C060E070") ! MAN1
2 CALL CHAR(104,"03030703030301030707070703010101C0C0E040E0C080C0E0E0E0E0C08080C0") ! MAN2
3 CALL CHAR(108,"030307030303010307070F0F03070607C0C0E040E0C080C0E0E0F0F0C060E070") ! MAN3
4 CALL CHAR(112,"0303070303030103070F1F1B03070C0EC0C0E040E0C080C0E0F0F8D8E0683830") ! MAN4
5 CALL CHAR(40,"0000000000000000000000FFFF55AA550000000000000000000000FFFF55AA55") ! PLATFORM
6 CALL CHAR(44,"FFFFFFFFFFFFFFFF") ! GROUND AT BOTTOM
 
! INITIALIZE SCREEN AND PLAYER POSITION WITH PLATFORM
10 CALL CLEAR::CALL MAGNIFY(3)
20 MAN=100::MX=168::MY=8
30 CALL HCHAR(24,1,44,32)::CALL SPRITE(#2,40,2,152,64)
 
! PLAYER CONTROL AND SUB TO PLAYER MOVEMENT
40 CALL JOYST(1,JY,JX)::CALL KEY(1,K,S)::GOSUB 1000
50 IF K=18 AND JY=0 THEN 100
60 IF K=18 AND JY=-4 THEN 200
70 IF K=18 AND JY=4 THEN 300
80 IF JY=-4 THEN 400
90 IF JY=4 THEN 500
95 GOTO 40
 
! JUMP UP
100 FOR Q=1 TO 4::MX=MX-4::GOSUB 1000::NEXT Q
110 FOR Q=1 TO 4::MX=MX-2::GOSUB 1000::NEXT Q
120 FOR Q=1 TO 4::GOSUB 1000::NEXT Q
130 FOR Q=1 TO 4::MX=MX+2::GOSUB 1000::NEXT Q
140 FOR Q=1 TO 4::MX=MX+4::GOSUB 1000::NEXT Q
150 GOTO 40
 
 
! JUMP BACK
200 FOR Q=1 TO 4::MX=MX-4::MY=MY-2::GOSUB 1000::NEXT Q
210 FOR Q=1 TO 4::MX=MX-2::MY=MY-2::GOSUB 1000::NEXT Q
220 FOR Q=1 TO 4::MY=MY-2::GOSUB 1000::NEXT Q
230 FOR Q=1 TO 4::MX=MX+2::MY=MY-2::GOSUB 1000::NEXT Q
240 FOR Q=1 TO 4::MX=MX+4::MY=MY-2::GOSUB 1000::NEXT Q
250 GOTO 40
 
! JUMP FORWARDS
300 FOR Q=1 TO 4::MX=MX-4::MY=MY+2::GOSUB 1000::NEXT Q
310 FOR Q=1 TO 4::MX=MX-2::MY=MY+2::GOSUB 1000::NEXT Q
320 FOR Q=1 TO 4::MY=MY+2::GOSUB 1000::NEXT Q
330 FOR Q=1 TO 4::MX=MX+2::MY=MY+2::GOSUB 1000::NEXT Q
340 FOR Q=1 TO 4::MX=MX+4::MY=MY+2::GOSUB 1000::NEXT Q
350 GOTO 40
 
! WALK BACK
400 MY=MY-4::GOTO 40
 
! WALK FORWARDS
500 MY=MY+4::GOTO 40
 
! PLAYER SPRITE AND COINCIDENCE
1000 IF MY<8 THEN 1005 ELSE 1010
1005 MY=8
1010 IF MY>248 THEN 1015 ELSE 1020
1015 MY=248
1020 MAN=MAN+4::IF MAN>112 THEN 1025 ELSE 1030
1025 MAN=100
1030 CALL SPRITE(#1,MAN,2,MX,MY)::CALL COINC(#1,#2,1,C)::IF C=-1 THEN 2000
1040 RETURN
 
 
! PLAYER STANDS ON PLATFORM
2000 MX=148::GOTO 40
 


#3 adamantyr OFFLINE  

adamantyr

    Stargunner

  • 1,363 posts

Posted Fri Aug 17, 2018 8:12 AM

Writing platform games is a technical challenge... and it's REALLY hard in Extended BASIC. The best platformers I've seen were R. Truman's Billy Ball games, and they are deceptively simple.

 

You have to reduce calculations as much as possible in an XB loop. One way you MAY accomplish this is to always have a sprite under your player character, an invisible one. Then you just do a COINC to check if there is ANY hits anywhere and so long as there is you assume he's "on" a platform. Another check elsewhere will make sure you have a graphic "platform" underneath and continuously recreates the invisible sprite underneath your player. If it's missing, you assume he's "falling".

 

That's how I managed to have sprite torpedoes using CALL MOTION in Space Trek; I just put an invisible "target" sprite on my end position and did a continuous COINC loop. COINC on position simply didn't move fast enough to catch it in boundaries.



#4 Retrospect OFFLINE  

Retrospect

    Stargunner

  • Topic Starter
  • 1,102 posts
  • Location:Wakefield, England

Posted Fri Aug 17, 2018 8:19 AM

 One way you MAY accomplish this is to always have a sprite under your player character, an invisible one. Then you just do a COINC to check if there is ANY hits anywhere and so long as there is you assume he's "on" a platform. Another check elsewhere will make sure you have a graphic "platform" underneath and continuously recreates the invisible sprite underneath your player. If it's missing, you assume he's "falling".

 

 

I'm going to try this!  Thank you Adamantyr, I never thought about having a sprite under the player :)

 

I can see this working.  



#5 Airshack OFFLINE  

Airshack

    Dragonstomper

  • 846 posts
  • Location:Phoenix, AZ

Posted Fri Aug 17, 2018 8:48 AM

Good answer! By using the second invisible sprite youre simply reassigning the origin of the character sprite from the top left corner (fixed by XB) to anywhere else you wish. In this case, reassigned to the bottom center. If you use two invisible sprites you may assign the two individual origins to the bottom left and bottom right of your player, or closer in to the outer edges of the main characters feet.

Of course, each invisible character will have a speed cost.

#6 mizapf OFFLINE  

mizapf

    River Patroller

  • 3,398 posts
  • Location:Germany

Posted Fri Aug 17, 2018 9:00 AM

COINC on position with automotion may miss a hit because the sprite jumps over that position. You always have to check an interval.



#7 Retrospect OFFLINE  

Retrospect

    Stargunner

  • Topic Starter
  • 1,102 posts
  • Location:Wakefield, England

Posted Fri Aug 17, 2018 9:14 AM

I rarely use automotion in sprites, what I tend to do, is have all my sprites move in intervals of 2 or 4 pixels, do all the calculations first, and then send to a subroutine that shows all the sprites in one hit, whilst checking for coincidences at the same time.  I find this to be the best method for me, to detect hits.

 

Of course, using this method it's best that the game should be compiled so as to reduce the hit on speed.  

 

I'm going to write another bit of code that uses the invisible sprites beneath, and perhaps on top of the player to detect the platforms. :)



#8 Sinphaltimus OFFLINE  

Sinphaltimus

    River Patroller

  • 2,515 posts
  • Distracted at the Keyboard
  • Location:Poconos, PA

Posted Sun Aug 19, 2018 10:20 AM

Interesting, I never considered using sprites when i started work on Zombi. all screens have a fixed platform pattern so i know the vertical position of every floor. I simply used sprites for the holes in the floor so a coinc detection would initiate a falling animation. I lock the player's vertical position as per the platform vertical position with pixel adjustments to line up correctly. Is there any benefit to using sprites vs fixed positions? I don't know that I'd enjoy a flickering platform unless that is the intended visual effect.

zmobi reference with sources: http://atariage.com/...bi#entry3693193



#9 Retrospect OFFLINE  

Retrospect

    Stargunner

  • Topic Starter
  • 1,102 posts
  • Location:Wakefield, England

Posted Sun Aug 19, 2018 2:54 PM

Working it with sprites might lead to less calculations having to be processed, making it all execute a bit tighter, but I don't know yet as I'm going to try both methods, sprites vs chars, and i'll see what the outcome is soon enough.  

 

I'm also currently working on a space shoot'em'up called Avaris.  It's top down, and in the style of "Schmup" on the MSX 2 so I'm juggling at the moment :)






0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users