370 likes | 535 Views
Practice04 – Platform Game. Goal. Tiled backgrounds Gravity Scrolling views Shooting. Platform Game. Game world 를 side 에서 보는 view Player 는 각기 다른 높이의 ground 에서 활동 Platform 간의 이동 Jump, Fall off, Climb ladders, Ropes … Game Objects Objects to pick up Enemies Door triggers
E N D
Goal • Tiled backgrounds • Gravity • Scrolling views • Shooting
Platform Game • Game world를 side에서 보는 view • Player는 각기 다른 높이의 ground에서 활동 • Platform간의 이동 • Jump, Fall off, Climb ladders, Ropes … • Game Objects • Objects to pick up • Enemies • Door triggers • Explosion triggers • Key for door open • Scrolling
Important Aspects in Platform Game • Natural motion for the main character • Interesting monsters and objects • A good level design with increasing difficulty
Platform 1 save as “platform1.gmd”
SprBlock, ObjBlock • Sprite 16 x 16 pixels • Completely black • Resize using (Transform > Resize Canvas) in Game Maker’s sprite editor • Not transparent • ObjBlock • Solid
SprPlayer • Ball.gif • 32 x 32
objPlayer (1) • Move along the floor • Getting stuck on the floor • Outside a platform: falling by gravity • Controlling with 3 cursor keys: up, left, right
objPlayer (2) • [EVENT] <left> keyboard • [Action] Jump to a given position: (-4, 0), relative • [EVENT] <right> keyboard • [Action] Jump to a given position: (4,0), relative • [EVENT] <up> keyboard • [Action] If there is a collision at a position • X=0, y=1, relative (1 below pixel) 바닥이 있어야만 jump가능 • [Action] set the vertical speed (move tab) • -10 (upward)
objPlayer (3) • [EVENT] Step • [Action] If a position is collision free (0, 1), relative • [Action] Set the gravity: direction=270(degree), gravity=0.5
objPlayer (4) • [EVENT] Step (계속) • [Action] Else • [Action] Set the gravity = 0 (end of else) • [Action] If a variable has a value (code tab) • vspeed, larger than, 12 • [Action] Set the vertical speed = 12
objPlayer (5) • [EVENT] Collision with block • [ACTION] Move to contact position (to align to the block) • direction = direction (currently moving direction) • Maximum = 12 • against = only solid objects • [ACTION] Vertical speed = 0
Room • Fill the bottom and sides with “blocks” • Some platforms
Platform 2 save as “platform2.gmd”
Player • sprPlayerLeft: player_left.gif • sprPlayerRight: player_right.gif • Remove “Precise collision checking” • Set “Bounding Box” to Manual • Delete previous “ball player” • objPlayer • set any sprite: sprPlayerRight • EVENT: <left> key • ACTION: Change the sprite “sprPlayerLeft” scale = 1 • EVENT: <right> key • ACTION: Change the sprite “sprPlayerRight” scale = 1
Tile Background (1) • bgrTiles: tiles.gif .. “make it Transparent” • Tiles of the same size • One pixel borders • Create a new room • Tiles tab > Select bgrTiles • Design your room
Tile Background (2) • Foreground tiles checkbox • tiles to show up in front of game characters • to make 3D feeling • Add “black block” in front of all platforms and boundary • Make “objBlock” invisible
Small blocks and more • … see the practice04.doc note
Platform 3 save as “platform3.gmd”
Monster (1) • sprMonster1Left, sprMonster1Right – walking monster • sprMonster2Left, sprMonster2Right – flying monster • Uncheck the “Precise collision detection” • Bounding box “manual”
Monster (2) • objMonster1 • objMonster2 • [EVENT] Create • [ACTION] Set Speed = 4 (monster1), 3(monster2) • [EVENT] Collision with objBlock • [ACTION] Reverse Horizontal Direction • [EVENT] Step > End Step • ACTION: If a variable has a value (code tab) • hspeed < 0 (즉, 왼쪽으로 움직일 때) • ACTION: Change Sprite to “objMonster1Left” • 같은 방법으로 hspeed > 0, “objMonster1Right”
Monster (3) • objMarker • blue square • invisible • Monster들에 • [Event] Collision with objMarker 추가 • [Action] objBlock 과 같게 • objMarker는 monster의 행동만을 바꾸는 역할
Monster (4) • objPlayer • [EVENT] Collision with Monster? • [ACTION] Play a dying sound “ao.wav” • [ACTION] Sleep 1000 msec • [ACTION] Restart the room • Monster1 dies when it is “hit” from above by player • Create “objMonster1Dead” • sprite “monster_1_flat.gif” • [EVENT] Create • [ACTION] Set the alarm0 = 10 • [EVENT] Alam0 event • [ACTION] Destroy the instance (self)
Catching Monster (1) • objPlayer의 • [EVENT] Collision with monster1 의 action list boijjing.wav stop other
Catching Monster (2) • Expression vspeed > 0 and y < other.y + 8 player가 위에서 아래로 향하고 있으며, 현재 위치가 monster1의 y 위치보다 위이다.
Valuable Objects • mushrooms.gif : 10 different mushrooms • mushroom object • [EVENT] Create • [ACTION] Set a variable • image_single • enter “random(10)” : randomly select from 0 to 9.999 • Place some mushrooms in the room • Player object • [EVENT] Collision with mushroom • [ACTION] Sound “Ploup.wav” • [ACTION] Increase score by 10, relative • [ACTION] Destroy instance - other
Reaching the next level • To the next level • Mushroom을 다 먹으면 문이 열리도록 한다. • Maze game때와 같이 door가 안 보이다가 나타나도록 함. • step event로 mushroom의 개수 check 한다.
Ladder - 1 • Removing gravity from the “step” event if the player is in contact with the ladder • Check if there is an object at position (0, 0), Relative that is of the type objLadder • If so, start a new block • Set the gravity to 0 • Set the vertical speed (vspeed) to 0 • Change the sprite into a climbing sprite, which you have to add first. You could use the player_up.gif image. Don't forget to set the bounding box to the same as the other player sprites. • End the block.
Ladder - 2 • <UP> keyboard event • Check if there is an object at position (0, 0), Relative of the type objLadder • If so, Start a new block • If a position is collision free (0, -3), Relative • Jump to position (0, -3), Relative • End the block. • <Down> keyboard • similar to <UP> but (0, 3) instead of (0, -3)
Views • Scrolling features • Use “Platform2.gmd” (News board in the course web) • Open room editor with “room1” • View tab • Enable the use of views • Select (view 0) • Visible when room starts • (Left, Top) = (0, 0) : upper left corner of view • (W, H) = (300, 200) : size of view region • (X, Y) = (0, 0) : current left-upper corner (initially 0,0) • Object to follow obj_player : changing (X, Y) • (HBor, VBor) = (64, 64) : margine • (HSp, VSp) = (4, 4) : speed of scrolling • Try the game! • Game Options Graphics Scale percentage in windowed mode 200 : scaling the pixel size double • Save the game as “Platform2-view1.gmd”
Shooting - 1 • Use “Platform3.gmd” • Save as “Platform3-shooting.gmd” • Two Sprites and Objects • objBullet: bullet.gif • objAmmo: Ammunition.gif • Setting # of bullets left • Object “objPlayer” • [EVENT] Create • [ACTION] Set the value of a variable • ammo, 0 • [EVENT] Collision with objAmmo • [ACTION] Set the value of a variable • ammo, 10, relative
Shooting - 2 • Object “objPlayer” • [EVENT] KeyPress <space> • If a variable has a value: ammo, 0, larger than • Block Start • Create an Instance (0, 0), relative, objBullet • Set the variable, ammo, -1, relative • Block end • Object “objBullet” • [EVENT] Create • If a variable has a value • objPlayer.sprite_index • sprPlayerLeft • Equal to • Move to the left with speed 12 • If objPlayer.sprite_index = sprPlayerRight, move to right with 12
Shooting - 3 • objBullet • [EVENT] Collision with objWall destroy itself • [EVENT] Collision with objMonsters • Score 50 points • Destroy other instance (monster) • Destory itself • Try to add sounds • for bullet creation • Collision bullet - monster
Debugging - 1 • Using “Platform3-shooting.gmd” • Save as “Platform3-debug.gmd” • Make the following room as the first room: (use tile first before block)
Debugging - 2 • Start the game in debug mode (F6 or red play arrow) • Play and extra debug window • Collect the ammo • move to the lower-left corner and fire some bullets • Add watch • click green plus sign in the debug window • Enter: instance_number(objBullet) • Enter: objPlayer.ammo • Fixing the error • objBullet • [EVENT] Outside Room (other type) • Destory the instance (self)
Debugging - 3 • Move player to jump up the platforms and finally to the ceiling • Player disappears! Where is it? • Add Watcher • objPlayer.y, objPlayer.x • falling … falling • Fixing • In objPlayer • [EVENT] Outside Room • If a variable has a value: y > room_height (below bottom) • Destroy the instance