Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
clicking stars game
this is another hello world game I make. this one is more for game design.

in this game, you click stars before they disappear, to make them reappear click the sun

hers the git repo:

[Image: star%20click.gif]

it wasn't easy to find how to change the alpha (transparency of img). but I found how with a small forum search.

no oop was also hard but I managed.

I see great potential in naalaa. with its pre built libs raycasting and a doom engine clone. would like t try these when I get more comfortable with it. I'll try porting all of my frameworks as functions, after all its all logic at the end of the day.

maybe I will make tutorials for naalaa in the future.
Nice, i made some changes in the code, this way works on both Linux and windows.

import "Keycodes.lib"
import "Speed.lib"

set window (screenw()-300 )/2, (screenh() - 400)/2, 520, 540

set redraw off

rem ---------asstes vars
star = 1
sun = 2

rem ------- load assets---------
load image star , "res/star.png"
load image sun , "res/sun.png"

rem star objects
rem create stars using function createStars
stars?[] = createStars(5)

rem sun object
s.x = rnd(200)
s.y = rnd(200)
s.w = 40
s.h = 40
s.type$ = "sun"

rem  player points
points = 0

rem player rank
rank$ = "none"

rem mouce cordenates
mx = mousex()
my = mousey()

rem ---------game loop

    set color 0, 0, 0

rem ---------------start game loop--------------

    rem --------------------- update
         rem update mouse variable to current mouse pos
        mx = mousex()
      my = mousey()
    c = clickObj(s,mx,my,stars)  
     c = clickStars(stars,mx,my,points)

    rem -------------------- render
      set color 255, 255, 255
      scale -1.1,-2.1
     draw image sun, s.x, s.y, 0, 0, s.w, s.h
        r = renderStars(stars)
    rem draw points to screen
    set caret 10, 10
    write "points: ",points
    rem print rank
    rank = rankHandale(points)
    set caret 150, 10
    write "rank: ",rank

rem ---------------end game loop----------------------
    _SPD_HoldFrame 60
until keydown(VK_SPACE, true) or not running()

rem -------------------------star funcs -------------------------

rem create stars

function createStars?[](num)
    for i = 0 to num-1
        s[i].x = rnd(400)
        s[i].y = rnd(400)
        s[i].w = 40
        s[i].h = 40
        s[i].alpha = 255
        s[i].type$ = "star"
    return s

rem end create stars

rem render stars
function renderStars(&s?[])
    star = 1
    for i = 0 to sizeof(s)-1

        set color 255, 255, 255, s[i].alpha
        draw image star , s[i].x, s[i].y    
        s[i].alpha = s[i].alpha -1

set color 255, 255, 255,255
    return 0
rem end render stars

rem handale stars being clicked
function clickStars(&s?[],mx,my,&points)
    for i = 0 to sizeof(s)-1

        c = clickObj(s[i],mx,my,s)    
        if c and s[i].alpha>10 then points = points +1;


rem end clickStars

rem -------------------------end star funcs -------------------------

rem -------------------------sun funcs -------------------------
function sunClick(&s?[])

    for i = 0 to sizeof(s)-1
        s[i].alpha = 255    

  return 0
rem -------------------------end sun funcs -------------------------

rem clickObj
function clickObj(&o?,mx,my,&s?[])
    rem debug
  set color 255, 0, 0
    rem draw rect o.x , o.y, o.w, o.h

    rem check if object is clicked
    if mousebutton(0) and    mx < o.w+o.x and mx > o.x and my < o.h+o.y and my > o.y
        rem move object to a randop position
        o.x = rnd(200)
      o.y = rnd(200)    
        if o.type$ = "sun"
            c = sunClick(s)
        return true


    return false
rem end clickObj

rem rank handler function (changes rank text )
function rankHandale$(points)
    if points > 10 then rank = "star clicker"
    if points > 20 then rank = "pro star clicker"
    if points > 25 then rank = "master star clicker"
    if points > 30 then rank = "no life"
    if points > 35 then rank = "you shod stop you know"
    if points > 40 then rank = "this game never ends"
    if points > 50 then rank = "good job you win"
    if points > 60 then rank = "you can stop now"

    return rank

I used the import to import the:
import "Keycodes.lib"
import "Speed.lib"

and then used the VK_SPACE instead of " ", also i used the _SPD_HoldFrame 60 instead of the wait, this way it runs on 60 fps in every machine, this is why we need the Speed.lib, i also rename the Star.png to star.png cause Linux is case sensitive.

Great job.
ok good to know ill do things that way from now on.
updated the git code.

Forum Jump:

Users browsing this thread: 1 Guest(s)