Insectoid @ Thu Jun 15, 2017 9:57 am wrote: That is fine.
Turing: |
setscreen ("graphics:900;550")
%--------------------------------------------------
const SPEED : int := 5 %player speed
var playerRight : int := Pic.FileNew ("assets/Hero.gif")
var playerLeft : int := Pic.FileNew ("assets/HeroFlip.gif")
var player : int := playerRight %player's either left or right, default:right
var levelOne : int := Pic.FileNew ("assets/grassland.gif")
var coin : int := Pic.FileNew ("assets/coin.gif")
var arrowDown : int := Pic.FileNew ("assets/arrowDown.gif")
var arrowUp : int := Pic.FileNew ("assets/arrowUp.gif")
var arrowLeft : int := Pic.FileNew ("assets/arrowLeft.gif")
var arrowRight : int := Pic.FileNew ("assets/arrowRight.gif")
var x : int := maxx div 2 - 32 %default x and y pos pf player
var y : int := maxy div 2 - 32
var coinX : int := Rand.Int (100, maxx - 100) %sets random x and y pos of fitst coin
var coinY : int := Rand.Int (100, maxy - 100)
var score : int := 0 %score starts at zero
var numArrows : int := 1
var randArrowDirection : int
var chars : array char of boolean %Input.KeyDown information
var arrowX : flexible array 1 .. numArrows of int
var arrowY : flexible array 1 .. numArrows of int
var arrowSpeed : flexible array 1 .. numArrows of int
var arrowDirection : flexible array 1 .. numArrows of string
var arrowImg : flexible array 1 .. numArrows of int
arrowX (1) := Rand.Int (107, maxx - 107) %sets first arrow's direction, x, y, and speed
arrowY (1) := maxy
arrowSpeed (1) := 3
arrowDirection (1) := "south"
arrowImg (1) := arrowDown
for i : 2 .. 5
numArrows := numArrows + 1 %add 1 to max amount of arrows in array
new arrowDirection, numArrows %resizes arrays
new arrowX, numArrows
new arrowY, numArrows
new arrowSpeed, numArrows
new arrowImg, numArrows
randArrowDirection := Rand.Int (1, 4) %sets new arrow to a random direction, x, y, and speed
if randArrowDirection = 1 then
arrowDirection (i ) := "north"
arrowImg (i ) := arrowUp
arrowX (i ) := Rand.Int (107, maxx - 107)
arrowY (i ) := - 16
arrowSpeed (i ) := Rand.Int (3, 5)
elsif randArrowDirection = 2 then
arrowDirection (i ) := "east"
arrowImg (i ) := arrowRight
arrowX (i ) := - 16
arrowY (i ) := Rand.Int (107, maxy - 107)
arrowSpeed (i ) := Rand.Int (3, 5)
elsif randArrowDirection = 3 then
arrowDirection (i ) := "south"
arrowImg (i ) := arrowDown
arrowX (i ) := Rand.Int (107, maxx - 107)
arrowY (i ) := maxy
arrowSpeed (i ) := Rand.Int (3, 5)
elsif randArrowDirection = 4 then
arrowDirection (i ) := "west"
arrowImg (i ) := arrowLeft
arrowX (i ) := maxx
arrowY (i ) := Rand.Int (107, maxy - 107)
arrowSpeed (i ) := Rand.Int (3, 5)
end if
end for
%--------------------------------------------------
process displayScore %used for testing score
loop
Input.KeyDown (chars )
if chars (' ') then
put score
delay (10)
end if
end loop
end displayScore
process displayArrow %used for testing arrow count
loop
Input.KeyDown (chars )
if chars ('p') then
put numArrows
delay (10)
end if
end loop
end displayArrow
process arrowHit
loop
for m : 1 .. numArrows
if Math.Distance (x + 32, y + 32, arrowX (m ) + 8, arrowY (m ) + 8) <= 30 then
for n : m .. numArrows - 1
arrowDirection (n ) := arrowDirection (n + 1)
arrowImg (n ) := arrowImg (n + 1)
arrowX (n ) := arrowX (n + 1)
arrowY (n ) := arrowY (n + 1)
arrowSpeed (n ) := arrowSpeed (n + 1)
end for
numArrows := numArrows - 1
new arrowDirection, numArrows %resizes arrays
new arrowX, numArrows
new arrowY, numArrows
new arrowSpeed, numArrows
new arrowImg, numArrows
end if
end for
end loop
end arrowHit
process coinCheck
loop
if Math.Distance (x + 32, y + 32, coinX + 16, coinY + 16) <= 20 then %checks if the distance between the middle of the player and the middle of the coin is less than 20 px
score := score + 1 %if so, add 1 to score
coinX := Rand.Int (100, maxx - 100) %sets new x and y pos of next coin
coinY := Rand.Int (100, maxy - 100)
end if
end loop
end coinCheck
process addArrow
loop
delay (2000) %how often a new arrow gets added
numArrows := numArrows + 1 %add 1 to max amount of arrows in array
new arrowDirection, numArrows %resizes arrays
new arrowX, numArrows
new arrowY, numArrows
new arrowSpeed, numArrows
new arrowImg, numArrows
randArrowDirection := Rand.Int (1, 4) %sets new arrow to a random direction, x, y, and speed
if randArrowDirection = 1 then
arrowDirection (numArrows ) := "north"
arrowImg (numArrows ) := arrowUp
arrowX (numArrows ) := Rand.Int (107, maxx - 107)
arrowY (numArrows ) := - 16
arrowSpeed (numArrows ) := Rand.Int (3, 5)
elsif randArrowDirection = 2 then
arrowDirection (numArrows ) := "east"
arrowImg (numArrows ) := arrowRight
arrowX (numArrows ) := - 16
arrowY (numArrows ) := Rand.Int (107, maxy - 107)
arrowSpeed (numArrows ) := Rand.Int (3, 5)
elsif randArrowDirection = 3 then
arrowDirection (numArrows ) := "south"
arrowImg (numArrows ) := arrowDown
arrowX (numArrows ) := Rand.Int (107, maxx - 107)
arrowY (numArrows ) := maxy
arrowSpeed (numArrows ) := Rand.Int (3, 5)
elsif randArrowDirection = 4 then
arrowDirection (numArrows ) := "west"
arrowImg (numArrows ) := arrowLeft
arrowX (numArrows ) := maxx
arrowY (numArrows ) := Rand.Int (107, maxy - 107)
arrowSpeed (numArrows ) := Rand.Int (3, 5)
end if
end loop
end addArrow
process arrowReset
loop
for k : 1 .. numArrows
if (arrowDirection (k ) = "north" and arrowY (k ) > maxy) or (arrowDirection (k ) = "east" and arrowX (k ) > maxx) or (arrowDirection (k ) = "south" and arrowY (k ) < - 16)
or (arrowDirection (k ) = "west" and arrowX (k ) < - 16) or (numArrows = 0) then
%if an arrow going in a specif direction reaches the boundaries, set new random direction, x, y, and speed
randArrowDirection := Rand.Int (1, 4)
if randArrowDirection = 1 then
arrowDirection (k ) := "north"
arrowImg (k ) := arrowUp
arrowX (k ) := Rand.Int (107, maxx - 107)
arrowY (k ) := - 16
arrowSpeed (k ) := Rand.Int (3, 5)
elsif randArrowDirection = 2 then
arrowDirection (k ) := "east"
arrowImg (k ) := arrowRight
arrowX (k ) := - 16
arrowY (k ) := Rand.Int (107, maxy - 107)
arrowSpeed (k ) := Rand.Int (3, 5)
elsif randArrowDirection = 3 then
arrowDirection (k ) := "south"
arrowImg (k ) := arrowDown
arrowX (k ) := Rand.Int (107, maxx - 107)
arrowY (k ) := maxy
arrowSpeed (k ) := Rand.Int (3, 5)
elsif randArrowDirection = 4 then
arrowDirection (k ) := "west"
arrowImg (k ) := arrowLeft
arrowX (k ) := maxx
arrowY (k ) := Rand.Int (107, maxy - 107)
arrowSpeed (k ) := Rand.Int (3, 5)
end if
end if
end for
end loop
end arrowReset
procedure move %movement, 8 directions
Input.KeyDown (chars )
if chars ('w') then
y := y + SPEED
end if
if chars ('a') then
x := x - SPEED
player := playerLeft
end if
if chars ('s') then
y := y - SPEED
end if
if chars ('d') then
x := x + SPEED
player := playerRight
end if
end move
procedure arrowDraw %draws all arrows
for i : 1 .. numArrows
Pic.Draw (arrowImg (i ), arrowX (i ), arrowY (i ), picMerge)
end for
end arrowDraw
procedure arrowMove %moves all arrows
for j : 1 .. numArrows
if arrowDirection (j ) = "north" then
arrowY (j ) := arrowY (j ) + arrowSpeed (j )
elsif arrowDirection (j ) = "east" then
arrowX (j ) := arrowX (j ) + arrowSpeed (j )
elsif arrowDirection (j ) = "south" then
arrowY (j ) := arrowY (j ) - arrowSpeed (j )
elsif arrowDirection (j ) = "west" then
arrowX (j ) := arrowX (j ) - arrowSpeed (j )
end if
end for
end arrowMove
procedure draw %all draws here to be organized
Pic.Draw (levelOne, 0, 0, picMerge)
Pic.Draw (coin, coinX, coinY, picMerge)
Pic.Draw (player, x, y, picMerge)
arrowDraw
arrowMove
move
View.Update
delay (15)
end draw
%---------------------------
%starts all functions to begin the game
fork displayScore
fork displayArrow
fork coinCheck
fork arrowReset
fork arrowHit
fork addArrow
loop
draw
end loop
%--------------------------
|
|