Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %Snake (ogodno)
- %VERSION 1.0
- % - Ready to play!
- %to do:
- % - read/write to file for high scores
- % - fix help button
- % - many more features
- %VERSION 1.1
- % - Added save data
- % - Bug fixes
- % - Added poise
- % - Fixed help button
- %to do:
- % -change method of snake drawing
- % -add item that resets snake length
- %NOTES%
- %Save file format:
- % high score
- % name
- % high score difficulty
- %NOTES
- %Setup
- setscreen ("graphics")
- View.Set ("graphics:800;800")
- %Variables
- var x1, y1, x2, y2 : int
- var Pc : int := 12 %Color of the point
- var chars : array char of boolean
- var direction : string := "none" %Tells what direction the snake is moving
- var Sx, Sy : int := 395
- var speed : int := 6
- var Ex, Ey : int
- var L, W : int
- var Ex2, Ey2 : int
- var Ec : int := 9
- var score : int := 0 %Stores score
- var font1 : int
- var difficulty : int
- var enemyW : int
- var titleF : int %Font var
- var mx, my, b : int %Mouse input vars
- var highscore : int := 0 %high score var
- var highscoreDIF : int := 0
- var name : string := "noJUAN"
- var stream : int
- var HS : int
- var NM : string
- var DF : int
- var savedataINT : array 1..2 of string
- %Fonts
- titleF := Font.New ("serif:20")
- %Procedures
- procedure restart
- cls
- drawfillbox (0, 0, 800, 800, black)
- locate (13, 40)
- color (12)
- colorback (black)
- put "YOU DIED"
- delay (2000)
- %if statements for high scores
- if score > highscore then
- highscoreDIF := difficulty
- cls
- locate (13, 40)
- colorback (black)
- put "HIGH SCORE! What is your name?: " ..
- color (white)
- get name
- delay (500)
- cls
- locate (13, 20)
- %Congrats message
- color (12)
- put "Congratulations " ..
- color (white)
- put name ..
- color (12)
- put ", you acheived a high score of " ..
- color (white)
- put score ..
- color (12)
- put "!" ..
- locate (14, 20)
- put "You beat the previous high score by " ..
- color (white)
- put (score - highscore) ..
- color (12)
- put "!"
- %End of congrats
- highscore := score
- open : stream, "save.txt", put
- put : stream, highscore
- put : stream, name
- put : stream, highscoreDIF
- close : stream
- elsif score = highscore then
- cls
- locate (20, 30)
- colorback (black)
- color (12)
- put "You matched the previous high score of ", score, " by ", name, " at ", highscoreDIF, "..."
- else
- cls
- locate (20, 30)
- colorback (black)
- %Put so close
- put "You were off of the high score " ..
- color (white)
- put highscore ..
- color (12)
- put " by " ..
- color (white)
- put highscore - score ..
- color (12)
- put " points!"
- delay (1000)
- locate (21, 30)
- put "Better luck next time!"
- delay (3000)
- end if
- %end of high scores if statements
- delay (6000)
- Sx := 395
- Sy := 395
- cls
- end restart
- procedure point
- %Make a random placement that doesnt go over the screen
- randint (x1, 0, 790)
- randint (y1, 0, 790)
- %Set the other x/y value to 8 units larger
- x2 := x1 + 8
- y2 := y1 + 8
- if whatdotcolor (x1, y1) = white then
- randint (x1, 0, 790)
- randint (y1, 0, 790)
- x2 := x1 + 8
- y2 := y1 + 8
- end if
- %Draw the point
- drawfillbox (x1, y1, x2, y2, Pc)
- end point
- process enemy () %Draws the enemy
- loop
- %Randomize size and pos of the enemy
- randint (Ex, 0, 790)
- randint (Ey, 0, 790)
- randint (L, 2, 15)
- randint (W, 1, 15)
- %Set the other point of the box
- Ex2 := Ex + W
- Ey2 := Ey + L
- drawfillbox (Ex, Ey, Ex2, Ey2, Ec)
- delay (enemyW)
- end loop
- end enemy
- procedure SCORE
- locate (1, 1)
- color (39)
- colorback (black)
- put "Score: ", score ..
- end SCORE
- procedure snek
- loop
- Input.KeyDown (chars)
- drawfillbox (Sx, Sy, Sx + 10, Sy + 10, white)
- %If statement for keyboard input
- if chars (KEY_UP_ARROW) then
- Sy := Sy + speed %Speed is a variable that can be changed earlier on in the code
- direction := "UP"
- score += 10
- SCORE
- elsif chars (KEY_LEFT_ARROW) then
- Sx := Sx - speed
- direction := "LEFT"
- score += 10
- SCORE
- elsif chars (KEY_RIGHT_ARROW) then
- Sx := Sx + speed
- direction := "RIGHT"
- score += 10
- SCORE
- elsif chars (KEY_DOWN_ARROW) then
- Sy := Sy - speed
- direction := "DOWN"
- score += 10
- SCORE
- end if
- %End of if statement
- %Collision detection
- if direction = "UP" then
- if whatdotcolor (Sx + 5, Sy + 11) = white or whatdotcolor (Sx + 5, Sy + 11) = 9 then
- restart
- exit
- end if
- elsif direction = "LEFT" then
- if whatdotcolor (Sx - 1, Sy + 5) = white or whatdotcolor (Sx - 1, Sy + 5) = 9 then
- restart
- exit
- end if
- elsif direction = "RIGHT" then
- if whatdotcolor (Sx + 11, Sy + 5) = white or whatdotcolor (Sx + 11, Sy + 5) = 9 then
- restart
- exit
- end if
- elsif direction = "DOWN" then
- if whatdotcolor (Sx + 5, Sy - 1) = white or whatdotcolor (Sx + 5, Sy - 1) = white then
- restart
- exit
- end if
- end if
- %End of collision detection
- %POINT DETECTION
- for i : 1 .. 10 %Checks for the point nearby
- if direction = "UP" then
- if whatdotcolor (Sx + i, Sy + 11) = 12 then
- drawfillbox (x1, y1, x2, y2, black)
- point
- score += 500
- SCORE
- elsif whatdotcolor (Sx - 1, Sy + i) = 9 then
- end if
- elsif direction = "LEFT" then
- if whatdotcolor (Sx - 1, Sy + i) = 12 then
- drawfillbox (x1, y1, x2, y2, black)
- point
- score += 500
- SCORE
- elsif whatdotcolor (Sx - 1, Sy + i) = 9 then
- end if
- elsif direction = "RIGHT" then
- if whatdotcolor (Sx + 11, Sy + i) = 12 then
- drawfillbox (x1, y1, x2, y2, black)
- point
- score += 500
- SCORE
- elsif whatdotcolor (Sx - 1, Sy + i) = 9 then
- end if
- elsif direction = "DOWN" then
- if whatdotcolor (Sx + i, Sy - 1) = 12 then
- drawfillbox (x1, y1, x2, y2, black)
- point
- score += 500
- SCORE
- elsif whatdotcolor (Sx - 1, Sy + i) = 9 then
- end if
- end if
- end for
- %END OF POINT DETECTION
- delay (50) %Delay so that it doesn't move crazy fast
- end loop
- end snek
- procedure LOAD
- open : stream, "save.txt", get
- get : stream, HS
- get : stream, NM
- get : stream, DF
- delay (50)
- close : stream
- highscore := HS
- name := NM
- highscoreDIF := DF
- end LOAD
- procedure Main
- score := 0
- %choose difficulty
- cls
- drawfillbox (0, 0, 800, 800, 50)
- colorback (50)
- color (black)
- put "Difficulty (1-5): " ..
- get difficulty
- cls
- locate (1, 1)
- color (black)
- %difficulty chosen
- %puts prev high score stats
- LOAD
- put "PREVIOUS HIGH SCORE: " ..
- color (12)
- put highscore ..
- color (black)
- put " BY " ..
- color (12)
- put name ..
- color (black)
- put " AT DIFFICULTY: " ..
- color (12)
- put highscoreDIF
- color (black)
- %previous high score stats
- %wait
- put "3..."
- delay (1000)
- put "2..."
- delay (1000)
- put "1..."
- delay (1000)
- %wait
- %CHANGE DIFFICULTY
- if difficulty = 1 then
- enemyW := 5000
- elsif difficulty = 2 then
- enemyW := 4000
- elsif difficulty = 3 then
- enemyW := 3000
- elsif difficulty = 4 then
- enemyW := 2000
- elsif difficulty = 5 then
- enemyW := 1000
- else
- enemyW := 3000
- end if
- drawfillbox (0, 0, 800, 800, black)
- point
- if difficulty >= 4 then %Enemies with difficulty of greater than 4
- fork enemy
- end if
- snek
- end Main
- %Main loop
- loop
- loop
- drawfillbox (0, 0, 800, 800, 50)
- Font.Draw ("By Saif K.", 0, 0, titleF, black)
- Font.Draw ("START", 380, 380, titleF, black)
- Font.Draw ("HELP", 380, 350, titleF, black)
- Mouse.Where (mx, my, b)
- if mx >= 380 and mx <= 463 and my >= 380 and my <= 397 and b = 1 then
- exit
- end if
- if mx >= 360 and mx <= 443 and my >= 360 and my <= 379 and b = 1 then
- drawfillbox (0, 0, 800, 800, 50)
- colorback (50)
- delay (200)
- cls
- locate (1, 1)
- %RULES/HOWTOPLAY
- put "HOW TO PLAY: "
- put " "
- put "1.Use arrow keys to move"
- put "2.500 points for red boxes"
- put "3.10 points while moving"
- put "4.At difficulty 4 or 5 avoid blue boxes!"
- put "5.Dont move backwards!"
- %RULES/HOWTOPLAY
- delay (5000)
- end if
- delay (50)
- cls
- end loop
- Main
- end loop
Advertisement
Add Comment
Please, Sign In to add comment