Player 3:
This is a female model I did ages ago... may as well make use of it!

Players.bb
Fixed sliding collision bug
This is a female model I did ages ago... may as well make use of it!

Players.bb
Fixed sliding collision bug
;========================================================================================== ;"players.bb" ;========================================================================================== ;Author: RobFarley?? Rims?? ;Purpose: Create, Manipulate, and Free Players. ; ;To do's: Break up player input with "event layer" (for key remapping/ networking/etc) ; ;History: ; - 9/5/2004 POedBoy ; ; Player_DrawAll() added instead of code floating in main loop ; ; - ?????? ?????? ; ; ; - 8/31/2004 POedBoy ; ; This module was created as a Tidy up/Maintenance move. Player specific code ; should now be centralized within this include. Player.player() array added allows ; direct indexing to a player(if used). Blackbox functions for Create/Destroy. Not too sure as ; what the accepted naming schemes are at this point soo please bear with. ; ;========================================================================================== ;TYPES ;========================================================================================== Type player Field ownedWeapons.weapon[MAX_WEAPONS] Field name$ Field x# Field y# Field speed# Field frame Field Clip Field ammo Field health# Field fpause,foot Field dir,credits Field id Field fireRate,tempFR Field weapon.weapon Field targetdir Field IsFiring,IsFiringTimer Field lives Field hurtCount ; this is used to play the hurt sound at a reasonable repeat rate Field score, kills, shots, doors End Type ;========================================================================================== ;GLOBALS AND ARRAYS ;========================================================================================== Dim Player.player(2);Array of types for direct indexing to all players ;not currently used -- needs the big group "okay" Global Player_Count = 0 ;used by screen centering code? Global playerradius = 20; too lazy to see what this does :) (was floating around in main include) Global playergfx = LoadAnimImage("gfx/player3.png",64,64,0,128) : MaskImage playergfx,255,0,255 Global player_one_start_x,player_one_start_y Global player_two_start_x,player_two_start_y Dim player_footfall(1) player_footfall(0)=LoadSound("sfx/step.wav") player_footfall(1)=LoadSound("sfx/step2.wav") ;========================================================================================== ;FUNCTIONS ;========================================================================================== Function Player_Create.player(Name$,X%,Y%,id%) Local pl.player = New player pl\name = Name$ pl\x = X pl\y = Y pl\frame = 0 pl\health = 100 pl\fpause = 0 pl\dir = 0 pl\id = id ;Ammo stuff pl\Clip = 2 pl\ammo = 15 pl\lives = 5 pl\speed = 2 CheckVis(Floor(pl\x/32),Floor(pl\y/32)) Player(id)=pl Return pl End Function Function Player_Free(pl.player) ;in the future -- if any resources/objects are linked to this player, ;they can be freed here-- ;... ;... ;for now-- just 'deletes' the player obj Delete pl.player End Function Function Player_UpdateAll() ScreenX=0 ScreenY=0 Player_Count=0 For pl.player = Each player move=False direct$="" mr=False ml=False mu=False md=False firing = False ; get input If control(pright,pl\id) And pl\x<7552 Then mr=True If control(pleft,pl\id) And pl\x>0 Then ml=True If control(pup,pl\id) And pl\y>0 Then mu=True If control(pdown,pl\id) And pl\y<7552 Then md=True ; weapons (player specific) If control(p_weapon1,pl\id) Then EquipWeapon(pl\id,getWeaponFromName(weaponBroadhurst)) If control(p_weapon2,pl\id) Then EquipWeapon(pl\id,getWeaponFromName(weaponDalton)) If control(p_weapon3,pl\id) Then EquipWeapon(pl\id,getWeaponFromName(weaponRobinson)) If control(p_weapon4,pl\id) Then EquipWeapon(pl\id,getWeaponFromName(weaponRyxx)) If control(p_weapon5,pl\id) Then EquipWeapon(pl\id,getWeaponFromName(weaponStyrling)) If control(p_weapon6,pl\id) Then EquipWeapon(pl\id,getWeaponFromName(weaponImpact)) If control(pAction,pl\id) Then runActionScript(pl) ; action key If control(pfire1,pl\id) fireWeapon(pl,pl\dir*22.5) firing = True EndIf ; restrict players to the visible screen If pl\x-GOffsetX > GraphicsWidth()-32 And mr=True Then mr=False If pl\x-GOffsetX < 32 And ml=True Then ml=False If pl\y-GOffsety > GraphicsHeight()-32 And md=True Then md=False If pl\y-GOffsety < 32 And mu=True Then mu=False ; Object Collision (walls, doors etc) If mr=True And ml=True Then ml=False If mu=True And md=True Then md=False If mr Then direct=direct + "R" If mu Then direct=direct + "U" If ml Then direct=direct + "L" If md Then direct=direct + "D" targetdir=-1 If direct = "U" Then targetdir=0 If direct = "RU" Then targetdir =2 If direct = "R" Then targetdir =4 If direct = "RD" Then targetdir = 6 If direct = "D" Then targetdir = 8 If direct = "LD" Then targetdir = 10 If direct = "L" Then targetdir = 12 If direct = "UL" Then targetdir = 14 newx = pl\x + (Sin(targetdir*22.5)*playerradius) newy = pl\y - (Cos(targetdir*22.5)*playerradius) xspeed# = (Sin(targetdir*22.5) * pl\speed) yspeed# = - (Cos(targetdir*22.5) * pl\speed) If mu Or mr Or md Or ml Then move=True If gettile(newx,pl\y,0) > 0 Then xspeed = 0 If gettile(pl\x,newy,0) > 0 Then yspeed = 0 tile=map(newx/32,newy/32,LayerObject) If tile>0 If Instr(objectdef(tile)\trigger,ScriptTrigger_OnTouch) RunScript(pl,objectdef(tile),ScriptTrigger_OnTouch,newx,newy) EndIf EndIf ; If you're Not firing change the direction you're looking If Not firing If targetdir>-1 Then pl\targetdir=targetdir If turndelay = 0 pl\dir = dirdif (pl\dir,pl\targetdir) EndIf EndIf ScreenX = ScreenX + pl\x ScreenY = ScreenY + pl\y Player_Count = Player_Count+1 ; collect objects If map(pl\x/32,pl\y/32,LayerObject)>0 If Instr(objectdef(map(pl\x/32,pl\y/32,LayerObject))\trigger,ScriptTrigger_OnOver) Then RunScript(pl,objectdef(map(pl\x/32,pl\y/32,LayerObject)),ScriptTrigger_OnOver,pl\x,pl\y) End If ;Animation If move = True pl\x = pl\x + xspeed pl\y = pl\y + yspeed pl\fpause = (pl\fpause + 1) Mod 10 If pl\fpause = 0 Then pl\frame = (pl\frame+1) Mod 8 EndIf ; MOVED: This is in player_affectHealth below. ;If pl\health = 0 Then ;TODO: Death of player ;End If Next End Function Function Player_GiveHealth(p.player, h#) p\health = p\health + h If p\health > 100 Then p\health = 100 End If End Function Function Player_DrawAll() Local pl.Player For pl.player = Each player DrawImage playergfx,pl\x-32-ScreenX,pl\y-32-ScreenY,pl\frame+(pl\dir*8);+(Pl\IsFiring*120) Next End Function Function keycheck(player,keyid%) For p.pickedup = Each pickedup If p\player = player And p\obj =keyid Then Delete p:Return True Next Return False End Function Function Player_affectHealth(p.player,h#) p\health = p\health - h ; this sound is repeated too quickly. ; I've added a hurtcount field to the player to slow it down If p\hurtcount=0 SoundPitch(hurt_sound,44000+Rand(-3000,3000)) playoneshot(hurt_sound,p\x,p\y) p\hurtcount=100 ; 100 is good, 10 is very fast, 200 is slow EndIf p\hurtcount=p\hurtcount-1 If p\health =< 0 Then ; rebirth p\health = 100 p\lives=p\lives-1 ; play spinny animation here If p\lives=0 ; replaced with end of game bit Cls Print "End of game" WaitKey End EndIf EndIf End Function ; moved here for editor compat. Function ShowMap(i) ; this is a very naff map, mainly intended for helping to test the vis functions p.player=Player(i) x=p\x/2:y=p\y/2 ;TODO: Initial position is dodgy, should be centred on the player... Repeat Cls drawmap(x,y,1,2) ; don't make it too easy, leave out the objects... ;-) ;TODO: trouble is, we need the doors... drawmap(x,y,3,2) drawmap(x,y,4,2) ;TODO: need to show players location! If control(pup,i) Then y=y-8 If control(pdown,i) Then y=y+8 If control(pleft,i) Then x=x-8 If control(pright,i) Then x=x+8 Flip Until KeyHit(1) FlushKeys End Function ;additional player specific functions can be added here later as needed.. ; temporarily moved from map.bb (editor will call for script functions) Function DamageTile(x,y,val) ;if the tile is not damageable then leave this function If x < 0 Then Return If y < 0 Then Return If x > 7552 Then Return If y > 7552 Then Return x = Floor(x/32) y = Floor(y/32) If map(x,y,LayerHits) <0 Then Return map(x,y,LayerHits) = map(x,y,LayerHits) - val ;if run out of hits If map(x,y,LayerHits) <1 Then If map(x,y,LayerObject)>0 Then If Instr(objectdef(map(x,y,LayerObject))\trigger,ScriptTrigger_OnDestroy) Then ;TODO: we probably need to keep track of which player owns which bullet, and pass that player in here RunScript(Player(1),objectdef(map(x,y,LayerObject)),ScriptTrigger_OnDestroy,x*32,y*32) Else ;default action for any other destructible object Map(x,y,LayerObject) = 0 Map(x,y,LayerCollision) = 0 End If End If EndIf End Function