Here are the graphic resources of Animation 2 (converted to .jpg and some renamed).
Here are some MIDI files I used in Animation 2.
eyeofthetiger.mid
greatestamericanhero.mid
ringoffire.mid
smb1-1up.mid
smb1-flag.mid
Here is the source code of Animation 2 (in Visual Basic).
"Form 1":
' add special 2d stuff (needed for gradient brush, there is 3d stuff!)
Imports System.Drawing.Drawing2D
' add system stuff (needed for sleep() command)
Imports System.Threading
Public Class Form1
' Declaration Section
Private canvas As Graphics
Private background As Bitmap
Private goatSprite As Bitmap
Private bucketSprite As Bitmap
Private sunsetBrush As Brush
Private x As Integer
Private y As Integer
Private w As Decimal
Private h As Decimal
Private bucketSpeed As Decimal
Private goatSpeed As Decimal
Private userQuits As Boolean
Private toOriginMatrix As Matrix
Private fromOriginMatrix As Matrix
Private rotateMatrix As Matrix
Private degreeIncrement As Decimal
Private radianIncrement As Decimal
Private counter As Integer
Private goatX As Integer
Private goatY As Integer
Private stationaryCanvas As Graphics
Private hiddenCanvas As Graphics
Private hiddenImage As Bitmap
Private lineX1 As Integer
Private lineX2 As Integer
Private lineY As Integer
'sprite animation variables
Private frameX As Integer
' goat is 125 x 125
Private frameWidth As Integer = 125
Private frameHeight As Integer = 125
Private frameRectangle As Rectangle
Private spriteScreenRectangle As Rectangle
Private slowAnimation As Integer
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
' make the label red and a funny thing about fire
Label1.Text = "oh no! FIRE!! look out, marty the goat!!!"
Label1.ForeColor = Color.Red
' start the canvas and make the background my fire picture
canvas = picAnimation.CreateGraphics
background = New Bitmap("fire.jpg")
canvas.DrawImage(background, 0, 0, picAnimation.Width, picAnimation.Height)
'time to animate!
goatSprite = New Bitmap("animatedgoat.bmp")
goatSprite.MakeTransparent(Color.Red)
'do frame rectangle first
frameX = 0
frameRectangle = New Rectangle(frameX, 0, frameWidth, frameHeight)
spriteScreenRectangle = New Rectangle(400, 350, 150, 120)
canvas.DrawImage(goatSprite, spriteScreenRectangle, frameRectangle, GraphicsUnit.Pixel)
'show bucket button
BucketButton.Visible = True
BucketButton.Enabled = True
'hide house button
btnStart.Visible = False
'start sound
player1.URL = "ringoffire.mid"
player1.Ctlcontrols.currentPosition = (1.8)
player1.Ctlcontrols.play()
End Sub
Private Sub BucketButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BucketButton.Click
player1.Ctlcontrols.stop()
player1.URL = "smb1-1up.mid"
player1.settings.playCount = 4
player1.Ctlcontrols.play()
'disable bucket button to allow for closing/stopping
BucketButton.Enabled = False
' start timer
timBucket.Enabled = True
'time to animate!
bucketSprite = New Bitmap("bucket3.bmp")
bucketSprite.MakeTransparent(Color.Blue)
x = -20
y = 20
w = 0
h = 0
bucketSpeed = 1
Do
canvas.DrawImage(bucketSprite, x, y, w, h)
x = x + bucketSpeed
y = y + bucketSpeed
w = w + 0.08
h = h + 0.08
Thread.Sleep(5)
Application.DoEvents()
Loop Until userQuits Or x >= 378
' bucket label
Label1.Text = "i has a magic bucket! (borrowed from walrus)"
Label1.ForeColor = Color.Yellow
'clean up
canvas.DrawImage(background, 0, 0, picAnimation.Width, picAnimation.Height)
'canvas.DrawImage(goatSprite, 400, 380)
canvas.DrawImage(goatSprite, spriteScreenRectangle, frameRectangle, GraphicsUnit.Pixel)
canvas.DrawImage(bucketSprite, x, y, w, h)
' show up button
upButton.Visible = True
'hide bucket button
BucketButton.Visible = False
stopButton.Visible = True
' initialize position variables for goat
x = 400
y = 350
goatSpeed = 5
End Sub
Private Sub upButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles upButton.Click
' new song
player1.settings.playCount = 1
player1.Ctlcontrols.currentPosition = (2)
player1.URL = "greatestamericanhero.mid"
player1.Ctlcontrols.play()
'disable upbutton to remove focus
upButton.Enabled = False
stopButton.Enabled = False
' set up anti-flicker
hiddenImage = New Bitmap(picAnimation.Width, picAnimation.Height)
hiddenCanvas = Graphics.FromImage(hiddenImage)
' show speed
Label2.Text = "speed = " & goatSpeed
Label2.Visible = True
Label3.Visible = True
'move the goat up to put out the fire (change to keyboard control with guiding text messages)
slowAnimation = 0
Do
hiddenCanvas.DrawImage(background, 0, 0, picAnimation.Width, picAnimation.Height)
'hiddenCanvas.DrawImage(goatSprite, x, y)
frameRectangle = New Rectangle(frameX, 0, frameWidth, frameHeight)
spriteScreenRectangle = New Rectangle(x, y, 150, 120)
hiddenCanvas.DrawImage(goatSprite, spriteScreenRectangle, frameRectangle, GraphicsUnit.Pixel)
hiddenCanvas.DrawImage(bucketSprite, x - 22, y + 68, w, h)
canvas.DrawImage(hiddenImage, 0, 0)
Thread.Sleep(5)
Application.DoEvents()
Loop Until userQuits
player1.Ctlcontrols.stop()
' top label
Label1.Text = "go marty! put out the fire!"
Label1.ForeColor = Color.Aqua
' hide up and stop button
upButton.Visible = False
stopButton.Visible = False
' show put out fire button when functional
outButton.Visible = True
player1.Ctlcontrols.currentPosition = (2)
player1.URL = "eyeofthetiger.mid"
player1.Ctlcontrols.play()
End Sub
Private Sub stopButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles stopButton.Click
userQuits = True
End Sub
Private Sub outButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles outButton.Click
' show put out fire button when functional
outButton.Visible = False
'make stationary canvas
hiddenImage = New Bitmap(picAnimation.Width, picAnimation.Height)
stationaryCanvas = Graphics.FromImage(hiddenImage)
hiddenCanvas = Graphics.FromImage(hiddenImage)
'fix x and y to refer to bucket, not goat
goatX = x
goatY = y
x = x - 22
y = y + 68
' initialize counter
counter = 0
' rotate bucket
degreeIncrement = 5
radianIncrement = -Math.PI / 180 * degreeIncrement
toOriginMatrix = New Matrix(1, 0, 0, 1, -x - w / 2, -y - h / 2)
rotateMatrix = New Matrix(Math.Cos(radianIncrement), Math.Sin(radianIncrement), -Math.Sin(radianIncrement), Math.Cos(radianIncrement), 0, 0)
fromOriginMatrix = New Matrix(1, 0, 0, 1, x + w / 2, y + h / 2)
' hide stop button
stopButton.Visible = False
userQuits = False
'rotate!
Do
stationaryCanvas.DrawImage(background, 0, 0, picAnimation.Width, picAnimation.Height)
spriteScreenRectangle = New Rectangle(goatX, goatY, 150, 120)
stationaryCanvas.DrawImage(goatSprite, spriteScreenRectangle, frameRectangle, GraphicsUnit.Pixel)
hiddenCanvas.DrawImage(bucketSprite, x, y, w, h)
canvas.DrawImage(hiddenImage, 0, 0)
hiddenCanvas.MultiplyTransform(toOriginMatrix, MatrixOrder.Append)
hiddenCanvas.MultiplyTransform(rotateMatrix, MatrixOrder.Append)
hiddenCanvas.MultiplyTransform(fromOriginMatrix, MatrixOrder.Append)
Thread.Sleep(5)
Application.DoEvents()
counter = counter + 1
Loop Until userQuits Or counter = 19
' fill screen with water texture
lineX1 = 0
lineY = picAnimation.Height
lineX2 = picAnimation.Width
Do
canvas.DrawLine(Pens.Aqua, lineX1, lineY, lineX2, lineY)
lineY = lineY - 1
Application.DoEvents()
Thread.Sleep(5)
Loop Until lineY = y + 40
' unrotate bucket
counter = 0
degreeIncrement = 5
radianIncrement = Math.PI / 180 * degreeIncrement
toOriginMatrix = New Matrix(1, 0, 0, 1, -x - w / 2, -y - h / 2)
rotateMatrix = New Matrix(Math.Cos(radianIncrement), Math.Sin(radianIncrement), -Math.Sin(radianIncrement), Math.Cos(radianIncrement), 0, 0)
fromOriginMatrix = New Matrix(1, 0, 0, 1, x + w / 2, y + h / 2)
Do
stationaryCanvas.DrawImage(background, 0, 0, picAnimation.Width, picAnimation.Height)
spriteScreenRectangle = New Rectangle(goatX, goatY, 150, 120)
stationaryCanvas.DrawImage(goatSprite, spriteScreenRectangle, frameRectangle, GraphicsUnit.Pixel)
stationaryCanvas.FillRectangle(Brushes.Aqua, lineX1, lineY, picAnimation.Width, picAnimation.Height - lineY)
hiddenCanvas.DrawImage(bucketSprite, x, y, w, h)
canvas.DrawImage(hiddenImage, 0, 0)
hiddenCanvas.MultiplyTransform(toOriginMatrix, MatrixOrder.Append)
hiddenCanvas.MultiplyTransform(rotateMatrix, MatrixOrder.Append)
hiddenCanvas.MultiplyTransform(fromOriginMatrix, MatrixOrder.Append)
Thread.Sleep(5)
Application.DoEvents()
counter = counter + 1
Loop Until userQuits Or counter = 19
' drain screen (background is grass landscape)
background = New Bitmap("grass.jpg")
sunsetBrush = New LinearGradientBrush(New Rectangle(0, 0, picAnimation.Width, picAnimation.Height), Color.DarkBlue, Color.SkyBlue, LinearGradientMode.Vertical)
Do
hiddenCanvas.DrawImage(background, 0, 0, picAnimation.Width, picAnimation.Height)
hiddenCanvas.FillRectangle(sunsetBrush, 0, 0, picAnimation.Width, 380)
hiddenCanvas.FillRectangle(Brushes.Aqua, lineX1, lineY, picAnimation.Width, picAnimation.Height - lineY)
spriteScreenRectangle = New Rectangle(goatX, goatY, 150, 120)
hiddenCanvas.DrawImage(goatSprite, spriteScreenRectangle, frameRectangle, GraphicsUnit.Pixel)
hiddenCanvas.DrawImage(bucketSprite, x, y, w, h)
canvas.DrawImage(hiddenImage, 0, 0)
lineY = lineY + 1
Loop Until lineY = picAnimation.Height
' go down to the grass and get a reward of dinner
slowAnimation = 0
Do
hiddenCanvas.DrawImage(background, 0, 0, picAnimation.Width, picAnimation.Height)
hiddenCanvas.FillRectangle(sunsetBrush, 0, 0, picAnimation.Width, 380)
frameRectangle = New Rectangle(frameX, 0, frameWidth, frameHeight)
spriteScreenRectangle = New Rectangle(goatX, goatY, 150, 120)
hiddenCanvas.DrawImage(goatSprite, spriteScreenRectangle, frameRectangle, GraphicsUnit.Pixel)
hiddenCanvas.DrawImage(bucketSprite, goatX - 22, goatY + 68, w, h)
canvas.DrawImage(hiddenImage, 0, 0)
goatY = goatY + 5
If slowAnimation = 3 Then
frameX = frameX + frameWidth
slowAnimation = 0
End If
If frameX >= goatSprite.Width - frameWidth Then
frameX = 0
End If
Thread.Sleep(5)
Application.DoEvents()
Loop Until goatY >= 320
player1.Ctlcontrols.stop()
player1.URL = "smb1-1up.mid"
player1.settings.playCount = 4
player1.Ctlcontrols.play()
' say goodbye to bucket
x = goatX - 22
goatY = goatY - 5
y = goatY + 68
Do
canvas.DrawImage(bucketSprite, x, y, w, h)
x = x - bucketSpeed
y = y - bucketSpeed
w = w - 0.08
h = h - 0.08
Thread.Sleep(5)
Application.DoEvents()
Loop Until userQuits Or x <= -40 Or w <= 0
player1.Ctlcontrols.stop()
hiddenCanvas.DrawImage(background, 0, 0, picAnimation.Width, picAnimation.Height)
hiddenCanvas.FillRectangle(sunsetBrush, 0, 0, picAnimation.Width, 380)
frameX = goatSprite.Width - frameWidth
frameRectangle = New Rectangle(frameX, 0, frameWidth, frameHeight)
spriteScreenRectangle = New Rectangle(goatX, goatY, 150, 120)
hiddenCanvas.DrawImage(goatSprite, spriteScreenRectangle, frameRectangle, GraphicsUnit.Pixel)
canvas.DrawImage(hiddenImage, 0, 0)
player1.settings.playCount = 1
player1.URL = "smb1-flag.mid"
player1.Ctlcontrols.play()
' top label
Label1.Text = "thank you bucket! marty gets to eat dinner now!!"
Label1.ForeColor = Color.White
' show story button with text = again!
btnStart.Text = "again!"
btnStart.Visible = True
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
player1.Ctlcontrols.stop()
userQuits = True
End Sub
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
' show speed
Label2.Text = "speed = " & goatSpeed
Label2.Visible = True
Label3.Visible = True
' set speed
If e.KeyCode = Keys.F1 And goatSpeed > 0 Then
goatSpeed = goatSpeed - 1
Label2.Text = "speed = " & goatSpeed
ElseIf e.KeyCode = Keys.F2 And goatSpeed < 10 Then
goatSpeed = goatSpeed + 1
Label2.Text = "speed = " & goatSpeed
End If
' move
If x > 32 + goatSpeed And e.KeyCode = Keys.Left Then
x = x - goatSpeed
slowAnimation = slowAnimation + 1
If slowAnimation = 3 Then
frameX = frameX + frameWidth
slowAnimation = 0
End if
ElseIf x < 452 - goatSpeed And e.KeyCode = Keys.Right Then
x = x + goatSpeed
slowAnimation = slowAnimation + 1
If slowAnimation = 3 Then
frameX = frameX + frameWidth
slowAnimation = 0
End If
ElseIf y > 0 + goatSpeed And e.KeyCode = Keys.Up Then
y = y - goatSpeed
slowAnimation = slowAnimation + 1
If slowAnimation = 3 Then
frameX = frameX + frameWidth
slowAnimation = 0
End If
ElseIf y < 387 - goatSpeed And e.KeyCode = Keys.Down Then
y = y + goatSpeed
slowAnimation = slowAnimation + 1
If slowAnimation = 3 Then
frameX = frameX + frameWidth
slowAnimation = 0
End If
End If
If frameX >= goatSprite.Width - frameWidth Then
frameX = 0
End If
End Sub
Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
'enable buttons
upButton.Enabled = True
stopButton.Enabled = True
'hide speed
Label2.Visible = False
Label3.Visible = False
End Sub
Private Sub timBucket_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timBucket.Tick
player1.Ctlcontrols.stop()
timBucket.Enabled = False
'could use for more interesting things, like animation, as well.
End Sub
End Class