Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tiny Adventure
#1
TINY ADVENTURE

 Objective of the game :
 Touch "Q" to finish the game

 Controls
 Movement : Left, Right
 Jump    : Up

 Hints :
 "Q" will be displayed if you eat
 the forbidden fruits "x" and reach score 20


Code:
'----------------
' INITIALIZATION
'----------------
'#win32
set window "Tiny Adventure",200,100,false,4
set redraw off

player   = []
fruit    = []
q        = []
camera   = []

'Initial Value
randomize clock()
player.x=width(primary)/2;player.y=height(primary)-15;player.img="P"
player.dx=2;player.dy=5;player.jump = 0
for i = 0 to 19; fruit[i] = [x:rnd(-80,280),y:rnd(50,80),img:"x"];next
q = [x:rnd(-80,280),y:rnd(20,50),img:"Q"]
camera.x = 0
score = 0

'--------------
' MAIN PROGRAM
'--------------
do   
    set color 0,0,0 ; cls 'clear screen
    Say(40,1,"Tiny Adventure")
   
    'camera's position on top left while the initial player's position in the middle
    camera.x = player.x - width(primary)/2
    camera.y = player.y - height(primary)/2

    'update mountain's position relative to the camera.x
    mountain =[-100-camera.x,90,0-camera.x,50,100-camera.x,70,200-camera.x,50,300-camera.x,90]
    
    'player's control   
    if keydown(KEY_LEFT) then
        player.x = player.x - player.dx 
    elseif keydown(KEY_RIGHT) then
        player.x = player.x + player.dx
    elseif keydown(KEY_UP) then
        player.y = player.y - player.dy; player.jump = 1 'jump
    endif  
   
    'collision detection between player and fruits
    for i = 0 to 19
        if (player.x>= fruit[i].x-10-camera.x and player.x <= fruit[i].x+10-camera.x) and
        (player.y >= fruit[i].y-10-camera.y and player.y <= fruit[i].y+10-camera.y) then
            score = score + 1
            fruit[i].y = -10 'out of screen
        endif
    next
   
    'collision detection between player and "Q"
    if (player.x>=q.x-10-camera.x and player.x<=q.x+10-camera.x) and
    (player.y>=q.y-10-camera.y and player.y<=q.y+10-camera.y) then
        Say(40,24,"Completed")
        q.y = -10 'out of screen
        redraw
        do;wait 1;until keydown(KEY_RETURN)
        end   
    endif
   
    'if the player jumps then goes down slowly
    if player.jump and player.y<=(height(primary)-15) then
        player.y = player.y + 1
        if player.y <=-4 then player.y = 0 'don't fly to outer space :-)
    endif   

    'boundaries
    if player.x <5 then 'left boundary
        player.x = player.x+5 
        Say(5,40,"Rrr")
    elseif player.x >width(primary)-5 then 'right boundary
        player.x = player.x-5
        Say(width(primary)-35,40,"Rrr")          
    endif

    'draw blue mountains , green fruits , white player and red "Q"
    set color 255,255,255; set caret width(primary)/2,12; center "Score :"+score
    set color 0,0,70 ; draw poly mountain,1 
    set color 0,150,0
        foreach i in fruit
            set caret fruit[i].x-camera.x,fruit[i].y
            wln fruit[i].img
        next
    if score >= 20 then
        set color 150,0,0;set caret q.x-camera.x,q.y; wln q.img
    endif
    set color 255,255,255; set caret player.x,player.y; wln player.img

    redraw
    fwait 30
until keydown(KEY_ESCAPE)

'-----------
' FUNCTIONS
'-----------
function Say(x,y,msg)
    set color 255,0,0; set caret x,y; wln msg
endfunc

You are welcomed to try the game, 
if you make some improvements on the game, 
please share on this thread 
so we can have fun together

Thank you   
Big Grin
Reply


Messages In This Thread
Tiny Adventure - by 1micha.elok - 02-16-2024, 10:17 AM
RE: Tiny Adventure - by johnno56 - 02-16-2024, 02:26 PM
RE: Tiny Adventure - by aliensoldier - 02-16-2024, 03:30 PM
RE: Tiny Adventure - by johnno56 - 02-16-2024, 07:48 PM
RE: Tiny Adventure - by Marcus - 02-16-2024, 09:40 PM
RE: Tiny Adventure - by 1micha.elok - 02-16-2024, 10:35 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)