I have plenty enough to show here, so I think it's worth it's own thread. I'm just trying to learn and have fun as usual, and I figured a mario like game would be a great place to start. All images were downloaded at http://gsarchives.net/index2.php?category=all&system=nes&game=super_mario_bros_3
and all sounds were downloaded at http://vgwallpaper.classicgaming.gamespy.com/sounds.htm
all are registered trademarks of nintendo. You will need to replace my images with your own before it will run, animation is not necessary to display my achievements.
I started with an unknown persons basic mario collision code, then built off of it, adding my own images and map etc..
have fun, crits and ideas wanted!
SuperStrict
'load images, sounds, and a few misc variables.
Global Tiles:TImage = LoadAnimImage("tiles.png", 32, 32, 0, 10)
Global mario:TImage = LoadImage("mario.png",0)
Global marioLeft:timage = LoadAnimImage("mario left.png", 16, 26, 0, 4)
Global marioright:timage = LoadAnimImage("mario right.png", 16, 26, 0, 4)
Global coin:TSound=LoadSound("Coin.wav",0)
Global win:TSound=LoadSound("win stage.wav",0)
Global start:TSound=LoadSound("start stage.wav",0)
Global music:TSound=LoadSound("sm3 grass.wav",0)
Global jump:TSound=LoadSound("mario jump.wav",0)
Global bump:TSound=LoadSound("cannon shot.wav",0)
Global score:Int=0
Global total:Int
Global tilex:Int
Global tiley:Int
Global i:Int
Global loadmap:Int=0
Graphics 1400 , 900 , 0
Const Gravity:Float = .1'gravity... have fun with this number :D
Type TPlayer
Field x:Float,y:Float
Field width:Float , height:Float
Field speedx:Float , speedy:Float
Field leftanim:Float= 0
Field rightanim:Float= - 1
Method Draw()'draw our hero!
'DrawImage mario, x , y' , width , height
If leftanim=>0 Then DrawImage marioleft, x, y, leftanim
If rightanim=>0 Then DrawImage marioright, x, y, rightanim
EndMethod
Method Update()
'ground friction
speedx:* .85
'x controls
'this section is messy but I will make it neater eventually
If KeyDown(key_left)
speedx = - 2
If KeyDown(KEY_LCONTROL) Then speedx = -4
leftanim=leftanim+.5
Rightanim = - 1
If leftanim=4 Then leftanim=0
EndIf
If KeyDown(KEY_right)
speedx = 2
If KeyDown(key_lcontrol) Then speedx = 4
rightanim=rightanim+.5
leftanim = - 1
If rightanim=4 Then rightanim=0
EndIf
If Not KeyDown(key_left) And Not KeyDown(key_right)
If leftanim=>0 Then leftanim=0
If rightanim=>0 Then rightanim=0
EndIf
'x movement
x:+ speedx
'if you ran into a wall
If map.rectcollide(x , y , width , height) Then
'move back out of the wall
x:- speedx
'stop your speed
speedx = 0
EndIf
'y controls (jump)
If KeyHit(key_up) Then
'make sure you are on the ground
If map.rectcollide(x , y + 1 , width , height) Then
'jump!
speedy = - 5
PlaySound jump
EndIf
EndIf
'y movement
speedy:+ gravity
y:+ speedy
'if you hit a wall
If map.rectcollide(x , y , width , height) Then
'move back out of the wall
y:- speedy
'stop your speed
speedy = 0
EndIf
EndMethod
EndType
Type TMap
Field width:Int , height:Int
Field array:Int[,]
Const tilesize:Int = 30
Field location:Int=0
Method Load()
Local x:Int,y:Int
Local line:String
ReadData width
ReadData height
array=New Int[width,height]
For y = 0 Until height
ReadData line
For x = 0 Until width
array[x , y] = Int(Mid(line , x + 1 , 1) )
Next
Next
EndMethod
Method Draw()
Local x:Int , y:Int
For y = 0 Until height
For x = 0 Until width
'draws the map
If array[x, y] = 0
DrawImage Tiles, x * TILESIZE, y * TILESIZE, 0
ElseIf array[x, y] = 1
DrawImage Tiles, x * TILESIZE, y * TILESIZE, 1
ElseIf array[x, y] = 2
DrawImage Tiles, x * TILESIZE, y * TILESIZE, 2
ElseIf array[x, y] = 3
DrawImage Tiles, x * TILESIZE, y * TILESIZE, 3
ElseIf array[x, y] = 4
DrawImage Tiles, x* TILESIZE, y * TILESIZE, 4
ElseIf array[x, y] = 5
DrawImage Tiles, x * TILESIZE,y * TILESIZE, 5
ElseIf array[x, y] = 6
DrawImage Tiles, x * TILESIZE, y * TILESIZE, 6
ElseIf array[x, y] = 7
DrawImage Tiles, x * TILESIZE, y * TILESIZE, 7
ElseIf array[x, y] = 8
DrawImage Tiles, x * TILESIZE, y * TILESIZE, 8
ElseIf array[x, y] = 9
DrawImage Tiles, x * TILESIZE, y * TILESIZE, 9
EndIf
Next
Next
EndMethod
'Returns True if the rectangle collides with the map.
'This one and only collision function can be used for everything.
'I did not make this, I can not claim to yet understand very much what is going on in here, though I did add all the "exceptions" to collisions.
Method RectCollide:Int(x:Float , y:Float , width:Float , height:Float)
Local x1:Int , y1:Int
Local x2:Int , y2:Int
'convert pixel positions to tile positions
x1 = x / tilesize
y1 = y / tilesize
x2 = (x + width) / tilesize
y2 = (y + height) / tilesize
'check each tile that the rect is in
For tiley = y1 To y2
For tilex = x1 To x2
If array[tilex , tiley] => 1 And array[tilex , tiley]<>6 And array[tilex , tiley]<>8 And array[tilex , tiley]<>9 And array[tilex , tiley]<>7 Then
Return True
EndIf
If array[tilex , tiley]=9
SetColor 255,255,255
you.draw()
map.draw()
SetColor 0,0,0
PlaySound win
Delay 4000
For i=1 To score
PlaySound coin
total=total+1
Delay 150
Next
score=0
Flip
Delay 1000
Cls
End
EndIf
If array[tilex , tiley]=8
array[tilex , tiley]= 0
PlaySound coin
score=score+1
EndIf
If array[tilex , tiley]=7
PlaySound bump
array[tilex , tiley]=1
you.x=you.x-you.speedx
you.y=you.y-you.speedy
EndIf
Next
Next
Return False
EndMethod
EndType
'//create a player
Global You:tplayer = New tplayer
you.x = 800
you.y = 800
you.width = 16
you.height = 26
Global Map:tmap = New tmap
map.Load()'loads the map below
PlaySound start'mario begin level sound
Repeat'main loop
Cls
SetColor 0,255,255
DrawRect 0,0,1500,1000
SetColor 255,255,255
you.update()
you.draw()
map.draw()
SetColor 0,0,0
DrawText "score: "+score,you.x-TextWidth("score: "+score)/2,you.y-13
SetColor 255,255,255
Flip
If KeyHit(key_escape) Then End
Forever
'0 is air, 1 is brick, 2 is left platform, 3 is middle platform, 4 is right platform, 5 is blue square, 6 is fake brick.
'7 is invisible brick, 8 is coin, 9 is flag.
'//map
DefData 150,30
DefData "1111111111111111111111111111111111111111111111"
DefData "1000000000000000000000000000000000000000000091"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1800000000000000000000000000000000000000000001"
DefData "1800000000000000000000000000000000000000000001"
DefData "1800000000000000000000000000000000000000000001"
DefData "1800800000000000000000000000000000000000000001"
DefData "1808000000000000000000000000000000000000000001"
DefData "1887000000000000000000000000000000000000000001"
DefData "1807000000000000000000000000000000000000000001"
DefData "1000700000000000000000000000000000000000000001"
DefData "1600070000000000000000000000000000000000000001"
DefData "1610007000700000000000000000000000000000000001"
DefData "1610000700700000000000000000000000000000000001"
DefData "1610000070706000000000000000000000000000000001"
DefData "1611000007701007770000000000000000000000000001"
DefData "1611100000701000000000000000000000000000000001"
DefData "1666610000071000000000000000000000000000000001"
DefData "1111611000007000000000000000000000000000000001"
DefData "1111611100000700000000000000000000000000000001"
DefData "1666611110000700000000000000000000000000000001"
DefData "1666611111000700000000000000000000000000000001"
DefData "1666611111100700000000000000000000000000000001"
DefData "1611111111117777000000000000000000000000000001"
DefData "1666666666666697000000000000000000000000000001"
DefData "1111111111111111111111111111111111111111111111"
Rem
this is just to copy and paste a cleared board for when you want to make a new map
DefData "1111111111111111111111111111111111111111111111"
DefData "1000000000000000000000000000000000000000000091"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1111111111111111111111111111111111111111111111"
EndRem
and all sounds were downloaded at http://vgwallpaper.classicgaming.gamespy.com/sounds.htm
all are registered trademarks of nintendo. You will need to replace my images with your own before it will run, animation is not necessary to display my achievements.
I started with an unknown persons basic mario collision code, then built off of it, adding my own images and map etc..
have fun, crits and ideas wanted!
SuperStrict
'load images, sounds, and a few misc variables.
Global Tiles:TImage = LoadAnimImage("tiles.png", 32, 32, 0, 10)
Global mario:TImage = LoadImage("mario.png",0)
Global marioLeft:timage = LoadAnimImage("mario left.png", 16, 26, 0, 4)
Global marioright:timage = LoadAnimImage("mario right.png", 16, 26, 0, 4)
Global coin:TSound=LoadSound("Coin.wav",0)
Global win:TSound=LoadSound("win stage.wav",0)
Global start:TSound=LoadSound("start stage.wav",0)
Global music:TSound=LoadSound("sm3 grass.wav",0)
Global jump:TSound=LoadSound("mario jump.wav",0)
Global bump:TSound=LoadSound("cannon shot.wav",0)
Global score:Int=0
Global total:Int
Global tilex:Int
Global tiley:Int
Global i:Int
Global loadmap:Int=0
Graphics 1400 , 900 , 0
Const Gravity:Float = .1'gravity... have fun with this number :D
Type TPlayer
Field x:Float,y:Float
Field width:Float , height:Float
Field speedx:Float , speedy:Float
Field leftanim:Float= 0
Field rightanim:Float= - 1
Method Draw()'draw our hero!
'DrawImage mario, x , y' , width , height
If leftanim=>0 Then DrawImage marioleft, x, y, leftanim
If rightanim=>0 Then DrawImage marioright, x, y, rightanim
EndMethod
Method Update()
'ground friction
speedx:* .85
'x controls
'this section is messy but I will make it neater eventually
If KeyDown(key_left)
speedx = - 2
If KeyDown(KEY_LCONTROL) Then speedx = -4
leftanim=leftanim+.5
Rightanim = - 1
If leftanim=4 Then leftanim=0
EndIf
If KeyDown(KEY_right)
speedx = 2
If KeyDown(key_lcontrol) Then speedx = 4
rightanim=rightanim+.5
leftanim = - 1
If rightanim=4 Then rightanim=0
EndIf
If Not KeyDown(key_left) And Not KeyDown(key_right)
If leftanim=>0 Then leftanim=0
If rightanim=>0 Then rightanim=0
EndIf
'x movement
x:+ speedx
'if you ran into a wall
If map.rectcollide(x , y , width , height) Then
'move back out of the wall
x:- speedx
'stop your speed
speedx = 0
EndIf
'y controls (jump)
If KeyHit(key_up) Then
'make sure you are on the ground
If map.rectcollide(x , y + 1 , width , height) Then
'jump!
speedy = - 5
PlaySound jump
EndIf
EndIf
'y movement
speedy:+ gravity
y:+ speedy
'if you hit a wall
If map.rectcollide(x , y , width , height) Then
'move back out of the wall
y:- speedy
'stop your speed
speedy = 0
EndIf
EndMethod
EndType
Type TMap
Field width:Int , height:Int
Field array:Int[,]
Const tilesize:Int = 30
Field location:Int=0
Method Load()
Local x:Int,y:Int
Local line:String
ReadData width
ReadData height
array=New Int[width,height]
For y = 0 Until height
ReadData line
For x = 0 Until width
array[x , y] = Int(Mid(line , x + 1 , 1) )
Next
Next
EndMethod
Method Draw()
Local x:Int , y:Int
For y = 0 Until height
For x = 0 Until width
'draws the map
If array[x, y] = 0
DrawImage Tiles, x * TILESIZE, y * TILESIZE, 0
ElseIf array[x, y] = 1
DrawImage Tiles, x * TILESIZE, y * TILESIZE, 1
ElseIf array[x, y] = 2
DrawImage Tiles, x * TILESIZE, y * TILESIZE, 2
ElseIf array[x, y] = 3
DrawImage Tiles, x * TILESIZE, y * TILESIZE, 3
ElseIf array[x, y] = 4
DrawImage Tiles, x* TILESIZE, y * TILESIZE, 4
ElseIf array[x, y] = 5
DrawImage Tiles, x * TILESIZE,y * TILESIZE, 5
ElseIf array[x, y] = 6
DrawImage Tiles, x * TILESIZE, y * TILESIZE, 6
ElseIf array[x, y] = 7
DrawImage Tiles, x * TILESIZE, y * TILESIZE, 7
ElseIf array[x, y] = 8
DrawImage Tiles, x * TILESIZE, y * TILESIZE, 8
ElseIf array[x, y] = 9
DrawImage Tiles, x * TILESIZE, y * TILESIZE, 9
EndIf
Next
Next
EndMethod
'Returns True if the rectangle collides with the map.
'This one and only collision function can be used for everything.
'I did not make this, I can not claim to yet understand very much what is going on in here, though I did add all the "exceptions" to collisions.
Method RectCollide:Int(x:Float , y:Float , width:Float , height:Float)
Local x1:Int , y1:Int
Local x2:Int , y2:Int
'convert pixel positions to tile positions
x1 = x / tilesize
y1 = y / tilesize
x2 = (x + width) / tilesize
y2 = (y + height) / tilesize
'check each tile that the rect is in
For tiley = y1 To y2
For tilex = x1 To x2
If array[tilex , tiley] => 1 And array[tilex , tiley]<>6 And array[tilex , tiley]<>8 And array[tilex , tiley]<>9 And array[tilex , tiley]<>7 Then
Return True
EndIf
If array[tilex , tiley]=9
SetColor 255,255,255
you.draw()
map.draw()
SetColor 0,0,0
PlaySound win
Delay 4000
For i=1 To score
PlaySound coin
total=total+1
Delay 150
Next
score=0
Flip
Delay 1000
Cls
End
EndIf
If array[tilex , tiley]=8
array[tilex , tiley]= 0
PlaySound coin
score=score+1
EndIf
If array[tilex , tiley]=7
PlaySound bump
array[tilex , tiley]=1
you.x=you.x-you.speedx
you.y=you.y-you.speedy
EndIf
Next
Next
Return False
EndMethod
EndType
'//create a player
Global You:tplayer = New tplayer
you.x = 800
you.y = 800
you.width = 16
you.height = 26
Global Map:tmap = New tmap
map.Load()'loads the map below
PlaySound start'mario begin level sound
Repeat'main loop
Cls
SetColor 0,255,255
DrawRect 0,0,1500,1000
SetColor 255,255,255
you.update()
you.draw()
map.draw()
SetColor 0,0,0
DrawText "score: "+score,you.x-TextWidth("score: "+score)/2,you.y-13
SetColor 255,255,255
Flip
If KeyHit(key_escape) Then End
Forever
'0 is air, 1 is brick, 2 is left platform, 3 is middle platform, 4 is right platform, 5 is blue square, 6 is fake brick.
'7 is invisible brick, 8 is coin, 9 is flag.
'//map
DefData 150,30
DefData "1111111111111111111111111111111111111111111111"
DefData "1000000000000000000000000000000000000000000091"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1800000000000000000000000000000000000000000001"
DefData "1800000000000000000000000000000000000000000001"
DefData "1800000000000000000000000000000000000000000001"
DefData "1800800000000000000000000000000000000000000001"
DefData "1808000000000000000000000000000000000000000001"
DefData "1887000000000000000000000000000000000000000001"
DefData "1807000000000000000000000000000000000000000001"
DefData "1000700000000000000000000000000000000000000001"
DefData "1600070000000000000000000000000000000000000001"
DefData "1610007000700000000000000000000000000000000001"
DefData "1610000700700000000000000000000000000000000001"
DefData "1610000070706000000000000000000000000000000001"
DefData "1611000007701007770000000000000000000000000001"
DefData "1611100000701000000000000000000000000000000001"
DefData "1666610000071000000000000000000000000000000001"
DefData "1111611000007000000000000000000000000000000001"
DefData "1111611100000700000000000000000000000000000001"
DefData "1666611110000700000000000000000000000000000001"
DefData "1666611111000700000000000000000000000000000001"
DefData "1666611111100700000000000000000000000000000001"
DefData "1611111111117777000000000000000000000000000001"
DefData "1666666666666697000000000000000000000000000001"
DefData "1111111111111111111111111111111111111111111111"
Rem
this is just to copy and paste a cleared board for when you want to make a new map
DefData "1111111111111111111111111111111111111111111111"
DefData "1000000000000000000000000000000000000000000091"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1000000000000000000000000000000000000000000001"
DefData "1111111111111111111111111111111111111111111111"
EndRem