So looked i add easy AI :)
[pbcode]
; PROJECT : BeatEmUp
; AUTHOR : Kevin Picone
; CREATED : 09.08.2008
; EDITED : 10.08.2008
; ---------------------------------------------------------------------
openscreen 248,168,32,1
; limit Frame rate to a Max of 60 frames (redraws per second)
Setfps 60
// Innclude the Animation libray
#include "FrameSheetAnims"
FrameSheetDefaultImageType=2
BackDrop=loadNewimage("bbackDro.bmp")
loadFXimage "anime.bmp",2
AnimFrameWidth=24
AnimFrameHeight=32
// First we'll create some images big enough to the WALK,PUNCH and KICK anaims
WalkingImage =NewFXImage(AnimFrameWidth*3,AnimFrameHeight)
PunchImage =NewFXImage(AnimFrameWidth*2,AnimFrameHeight)
KickImage =NewFXImage(AnimFrameWidth*3,AnimFrameHeight)
// Tell PB to
//Grab the Walking Frames from the Animation image
CopyRect 2,0,0,AnimFrameWidth*3,AnimFraMeHeight, WalkingIMage,0,0
//Grab the Punch Frames from the Animation image
CopyRect 2,AnimFrameWidth*3,0,AnimFrameWidth*5,AnimFraMeHeight, PunchIMage,0,0
//Grab the Kick Frames from the Animation image
CopyRect 2,AnimFrameWidth*5,0,AnimFrameWidth*8,AnimFraMeHeight, KickIMage,0,0
// DRaw the Anims to the screen so we can validate we're grabbed the correct animation parts..
drawimage WalkingImage,0,AnimFrameHeight*0,false
drawimage PunchImage,0,AnimFrameHeight*1,false
drawimage KickImage,0,AnimFrameHeight*2,false
Sync
waitkey
waitnokey
// create the Frames for each animation
WalkingFrameSheet =NewFramesheet(WalkingImage,24,32,3,-1)
PunchFrameSheet =NewFramesheet(PunchImage,24,32,2,-1)
KickFrameSheet =NewFramesheet(KickImage,24,32,3,-1)
walkenemi=loadframesheet("anime1.bmp",16,32,-1)
// CReate a Walking /Punch anims for us to use
WalkAnim =NewAnim(WalkingFrameSheet,7)
PunchAnim =NewAnim(PunchFrameSheet,7)
KickAnim =NewAnim(KickFrameSheet,7)
walken =newAnim(walkenemi,7)
Type tObject
Sprite ; The Sprite This objects uses for displaying this character
X# ; Objects X coordinate on the screen
Y# ; Objects Y coordinate on the screen
Speed# ; Speed Object is moving
CurrentAnim ; The Animation this character ius currently using
Walking ; Flag stores if the Object is WALKING or not
Punching ; Flag stores if the Object is Punching or not
Kicking ; Flag stores if the Object is KICKING or not
Jumping ; Flag to indicate if the object uis jumping
JumpHeight# ; height (in pixels) this charcter can jump
JumpAngle# ; When jumping object moves this angle from 0 to 180 degrees,
; when the object is drawn, it displaced on the Y axis by SIN() of jump angle#
EndType
Dim Player as tObject
Player.X=1
Player.Y=143
Player.Speed=1
Player.JumpHeight# =35 ; object can jump 100 pixels
// set play to use thre WALK ANIM when we start
Player.CurrentAnim = WalkANIM
Player.Sprite =NewSprite(0,0,0)
spritedrawmode player.Sprite,2
AutoCenterSpriteHandle player.Sprite,true
createsprite 5
spritedrawmode 5,2
AutoCenterSpriteHandle 5,true
xai#=240
yai#=143
speeden#=0.2
// -------------------------------------
// Start of Programs MAIN LOOP
// -------------------------------------
Do
setcursor 0,0
drawimage BackDrop,0,0,false
// -------------------------------------
// Control Player (ARROW KEYS)
// -------------------------------------
Player.Walking=false
// Check if the player isn't KICKING or PUNCHING
// ------------------------------------------------
if PLayer.Punching=false and PLayer.Kicking=False
// If not kick or punching then allow to move
if LeftKey()=true
// MOve the player left
Player.x#=Player.x#-PLayer.Speed#
player.Walking=true
Player.CurrentAnim = WalkAnim
scalespriteX 1,-1
endif
if Player.x#<0 then Player.x#=0
if RightKey()=true
// MOve the player RIGHT
Player.x#=Player.x#+PLayer.Speed#
player.Walking=true
Player.CurrentAnim = WalkAnim
scalespriteX 1,1
endif
if Player.x#>248 then Player.x#=248
if UpKey()=true
// MOve the player UP
Player.Y#=Player.Y#-PLayer.Speed#
player.Walking=true
Player.CurrentAnim = WalkAnim
endif
if Player.y#<125 then Player.y#=125
if DownKey()=true
// MOve the player DOWN
Player.Y#=Player.Y#+PLayer.Speed#
player.Walking=true
Player.CurrentAnim = WalkAnim
endif
if Player.y#>150 then Player.y#=150
endif
// =======================================
// Check if the A key is pressed, PUnching
// =======================================
if PLayer.Punching=False and Player.Kicking=False
// If the A key is pressed, then throw a punch
if keystate(30)=true
player.walking =false
PLayer.Punching=true
PLayer.CurrentAnim =PunchAnim
AnimMethod(PLayer.CurrentAnim, AnimMethod_ForwardOnce)
endif
// If the Z key is pressed, then KICK
if keystate(44)=true
player.walking =false
PLayer.Kicking=true
PLayer.CurrentAnim =KickAnim
AnimMethod(PLayer.CurrentAnim, AnimMethod_ForwardOnce)
endif
endif
// =======================================
// UPDATE PUNCH ANIM if punching
// =======================================
if PLayer.Punching=TRUE
If GetAnimComplete(Player.CurrentAnim)=true
Player.Punching=False
PLayer.CurrentAnim =WalkAnim
else
stepanim(Player.CurrentAnim)
endif
endif
// =======================================
// UPDATE KICK ANIM is kicking
// =======================================
if Player.Kicking=TRUE
If GetAnimComplete(Player.CurrentAnim)=true
Player.Kicking=False
PLayer.CurrentAnim =WalkAnim
else
stepanim(Player.CurrentAnim)
endif
endif
// Check if player is jumping ?
if player.Jumping=false
; If not, we check the LEFT CTRL key to jump
if Ctrlkeys(1)=true
player.jumping=true
player.JumpAngle#=0
endif
endif
// if the player is walking, then update the walk animation
if Player.Walking=true
stepanim(WalkAnim)
endif
// Update the Jump angle
if Player.jumping=true
JumpAngle#=player.JumpAngle#+3
if JumpAngle#=>180
Player.Jumping=false
JumpAngle#=0
endif
Player.JumpAngle#=JumpAngle#
endif
if PLayer.Y#<yai# then yai#=yai#-speeden#
if PLayer.Y#>yai# then yai#=yai#+speeden#
if PLayer.X#<xai# then xai#=xai#-speeden#:scalespriteX 5,-1:stepanim(walken)
if PLayer.X#>xai# then xai#=xai#+speeden#:scalespriteX 5,1:stepanim(walken)
//distance for player stops
if distance(PLayer.X#,xai#,PLayer.Y#,yai#)<14 and PLayer.X#-xai#>0 then xai#=xai#-speeden#
if distance(PLayer.X#,xai#,PLayer.Y#,yai#)<14 and PLayer.X#-xai#<0 then xai#=xai#+speeden#
if distance(PLayer.X#,xai#,PLayer.Y#,yai#)<14 and PLayer.X#-xai#=0 then xai#=xai#+speeden#
//if player and enemi point
if distance(PLayer.X#,xai#,PLayer.Y#,yai#)<14 and PLayer.X#>xai# then xai#=xai#-speeden#
if distance(PLayer.X#,xai#,PLayer.Y#,yai#)<14 and PLayer.X#<xai then xai#=xai#+speeden#
//vertical
if distance(PLayer.X#,xai#,PLayer.Y#,yai)<14 and PLayer.Y#>yai# then xai#=xai#+speeden#
if distance(PLayer.X#,xai#,PLayer.Y#,yai#)<14 and PLayer.Y#<yai# then xai#=xai#+speeden#
// -------------------------------------
// Draw Player as ellipse
// -------------------------------------
;add the players jumping offset to the players screen position
Ypos#=PLayer.Y# -Sin(Player.JumpAngle#)*Player.JumpHeight#
// draw the characters shadow bellow him
Ellipsec PLayer.X#,PLayer.Y#+16,9,4,true, Rgb(0,0,0)
Ellipsec xai#,yai#+16,9,4,true, Rgb(0,0,0)
// Set this players current Animation frame
SpriteImage Player.Sprite,GetAnimImage(Player.CurrentAnim)
// POsition the sprite
Positionsprite player.Sprite,Player.x#,Ypos#
spriteimage 5,GetAnimImage(walken)
positionsprite 5,xai#,yai#
// Draw all the sprites
Drawallsprites
// -------------------------------------
// DRaw the screen, and loop back to the do statement ot keep program running
// -------------------------------------
Sync
loop
function distance(x1#,x2#,y1#,y2#)
a#=x1#-x2#
b#=y1#-y2#
c#=sqrt(a#*a#+b#*b#)
endfunction c#
[/pbcode]
Looks good, if i don't say so myself :).. Bbut to make it easier for others to test, you should zip up the whole project folder and just post that. Then others can just download the one file, unzip and run it.
Yea Thanks Kevin for code and idea for .rar=)
I haven't dl the game, but it reminds me of River City Ransom for the NES. Did you drew that yourself?
Any progress with this ?
Quote from: eatfishy on October 20, 2008, 07:40:47 PM
I haven't dl the game, but it reminds me of River City Ransom for the NES. Did you drew that yourself?
i do screenshots=)
Quote from: kevin on October 26, 2008, 09:16:18 PM
Any progress with this ?
i work time to time. many time deprives training. In a short time return the game to further writing
And learn this game source code =) http://www.senileteam.com/bordownload.html#p1929
That's a nice looking game. Have you thought about porting the 'game engine' to playbasic ? :)
No I study logic of the building of the game itself. I want to do its beat'em up think. And think beside I shall not appear of the problems to do this in PlayBasic.=)
Plz help me ;)! I can not understand as better build collision boxes :P Need use RectHitSprite comands and etc. ?
You haven't told us exactly what you're trying to do ?
Quote from: kevin on January 04, 2009, 08:40:27 AM
You haven't told us exactly what you're trying to do ?
Colision for kicking and punching=)
When you punch, compare the 'fist' rect or circle perhaps with the hit zone(s) of the bad guy.
When you kick, compare the 'foot' rect or circle perhaps with the hit zone(s) of the bad guy
Also, here's replacement Distance SUB
Psub distance(x1#,x2#,y1#,y2#)
result#=GetDistance2D(x1#,y1#,x2#,y2#)
endPsub result#
Thanks!!!!!!!!! i try its=)
recently returned to writing this game.
and faced with the problem of adding animation, then why the animation is mixed = (
At around line 50 you're loading over image #3, without regard if it's in use or not. To solve this move to dynamic image creation. Ie LoadNEWfximage() rather than LoadFXImage
[pbcode]
; load the image with all the frames on it.
ThisIMage=loadNewFXimage("anime1.bmp")
; grab them
WImageEn =NewFXImage(AnimFrameWidth*3,AnimFrameHeight)
PImageEn =NewFXImage(AnimFrameWidth*2,AnimFrameHeight)
CopyRect ThisIMage,0,0,AnimFrameWidth*3,AnimFraMeHeight,WImageEn,0,0
CopyRect ThisIMage,AnimFrameWidth*3,0,AnimFrameWidth*5,AnimFraMeHeight,PImageEn ,0,0
drawimage WImageEn,0,AnimFrameHeight*3,false
drawimage PImageEn,0,AnimFrameHeight*4,false
; Delete this temp image as it's of no use anymore
DeleteImage ThisIMage
[/pbcode]
Thank you Kevin!
now I understood the logic FxImage.
As outlined in the Help->About->NamingConventions in the documentation, there's two approaches in PB. The CREATE (explicit) or NEW (dynamic). With explicit commands such as CreateImage()/LoadImage, the user specifies the Media Index they wish to use. In this case, the onus is upon the user to ensure this is valid (free, not already in use) media index. If it's not, any existing media will be destroyed when the new media is created/loaded.
Any command with NEW keyword prefix, such as NewImage(), LoadNewImage() use dynamic media index allocation. Dynamic allocation means PB returns a new Media Index for you that's not in use. Making it impossible to clash with existing media.