Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Fish game
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
pj_ladd12




PostPosted: Wed Aug 23, 2006 9:39 pm   Post subject: Fish game

Here is a start to my game, use arrow keys to move



any comments wud be cool thank you!


code:

setscreen ("offscreenonly;graphics:530;330;position:100;100;nobuttonbar") %settings
var swim : array char of boolean
var xpos, ypos : real := 200
var bodyxsize : int := 30
var bodyysize : int := 18
var shadowx : real
var shadowxsize : real
var speed : real := 0
var die : int := 0
var sidespeed : real := 0
var bubblex, bubbley, bubbler : array 1 .. 5 of real
var grassx, grassy : array 0 .. 20 of int
shadowxsize := 40
for i : 1 .. 5 %5 random bubbles
    bubblex (i) := Rand.Int (round (xpos + 15), round (xpos + 28))
    bubbley (i) := Rand.Int (round (ypos - 10), round (ypos + 10))
    bubbler (i) := Rand.Int (1, 3)
end for
for i : 0 .. 20
    grassx (i) := 0 %weeds
    grassy (i) := 0
end for
%%
procedure background
    for i : 0 .. 20 %weeds
        Draw.ThickLine (grassx (i) + i * 50 + 16, grassy (i) + 40, grassx (i) + i * 50, grassy (i), 3, 190)
        Draw.ThickLine (grassx (i) + i * 50 + 10, grassy (i) + 64, grassx (i) + i * 50, grassy (i), 3, green)
        Draw.ThickLine (grassx (i) + i * 50 + 20, grassy (i) + 50, grassx (i) + i * 50 + 25, grassy (i), 3, 190)
        Draw.ThickLine (grassx (i) + i * 50 + 12, grassy (i) + 40, grassx (i) + i * 50 + 18, grassy (i), 3, 7)
        Draw.ThickLine (grassx (i) + i * 50 + 32, grassy (i) + 53, grassx (i) + i * 50 + 28, grassy (i), 3, green)
        Draw.ThickLine (grassx (i) + i * 50 + 38, grassy (i) + 40, grassx (i) + i * 50 + 35, grassy (i), 3, 7)
        Draw.ThickLine (grassx (i) + i * 50 + 48, grassy (i) + 50, grassx (i) + i * 50 + 35, grassy (i), 3, 190)
        Draw.ThickLine (grassx (i) + i * 50 + 48, grassy (i) + 60, grassx (i) + i * 50 + 45, grassy (i), 3, green)
    end for
end background
%%
procedure fish
    shadowx := xpos %shadow
    Input.KeyDown (swim)
    drawfilloval (round (xpos), round (ypos), bodyxsize, bodyysize, blue) %fishs' body
    drawfilloval (round (xpos + 10), round (ypos + 8), 6, 6, 7)
    drawfilloval (round (xpos + 13), round (ypos + 5), 1, 1, 0)
    drawfilloval (round (shadowx), 5, round (shadowxsize - 8), bodyysize - 22, 7) %shadow
    Draw.ThickLine (round (xpos - 50), round (ypos + 3), round (xpos - bodyxsize), round (ypos), 3, 7) %tail
    Draw.ThickLine (round (xpos - 53), round (ypos + 7), round (xpos - bodyxsize), round (ypos + 3), 2, 7)
    Draw.ThickLine (round (xpos - 53), round (ypos - 7), round (xpos - bodyxsize), round (ypos - 3), 2, 7)
    Draw.ThickLine (round (xpos - 53), round (ypos - 2), round (xpos - bodyxsize), round (ypos - 1), 3, 7)
    %controls
    if swim (KEY_UP_ARROW) then
        speed += 0.01 %speed increase
    end if
    if swim (KEY_DOWN_ARROW) then
        speed -= 0.01 %decrease
    end if
    if swim (KEY_LEFT_ARROW) then
        sidespeed -= 0.01 %""
    end if
    if swim (KEY_RIGHT_ARROW) then
        sidespeed += 0.01  %""
    end if
    %controls
    %speed
    xpos += sidespeed %speed
    ypos += speed %""
    %speed
    %boundries
    if xpos > maxx + bodyxsize + 24 then
        xpos := 0 - bodyxsize %boundries
    end if
    if xpos < 0 - bodyxsize then
        xpos := maxx + bodyxsize + 24
    end if
    if ypos > maxy + bodyysize then
        ypos := 0 - bodyysize
    end if
    if ypos < 0 - bodyysize then
        ypos := maxy + bodyysize
    end if
    %boundries
    %limit speed
    if speed > 2 then
        speed := 2 %stops at 2
    end if
    if speed < -2 then
        speed := -2
    end if
    if sidespeed > 2 then
        sidespeed := 2
    end if
    if sidespeed < -2 then
        sidespeed := -2
    end if
    %limit speed
    %shadow settings
    if speed >= 0.1 then
        shadowxsize += 0.1 %shadow increases if fish swims upward
    elsif speed <= -0.1 then
        shadowxsize -= 0.1
    end if
    if ypos >= maxy + bodyysize then %fish is at top
        shadowxsize := 40
    end if
    if ypos <= 0 - bodyysize then %fish is at bottom
        shadowxsize := 40
    end if
    %shadow settings
end fish
%%
procedure bubbles
    for i : 1 .. 5
        drawoval (round (bubblex (i)), round (bubbley (i)), round (bubbler (i)), round (bubbler (i)), 8)
        bubbley (i) += .1 %speed
        if bubbley (i) > maxy + 10 then %if get to top
            bubblex (i) := Rand.Int (round (xpos + 15), round (xpos + 28))
            bubbley (i) := Rand.Int (round (ypos - 10), round (ypos + 10))
            bubbler (i) := Rand.Int (1, 3)
        end if
    end for
end bubbles
%%
type otherfish :
    record
        fishx : int
        fishy : int
        fishradius : int
    end record
var bad : array 1 .. 6 of otherfish
for i : 1 .. 6
    randint (bad (i).fishx, maxx, maxx + 200)
    randint (bad (i).fishy, 30, maxy - 30)
    randint (bad (i).fishradius, 6, 25)
end for
procedure enemies
    for i : 1 .. 6
        Draw.ThickLine (bad (i).fishx, bad (i).fishy, bad (i).fishx + 55, bad (i).fishy + 6, 2, 7)
        Draw.ThickLine (bad (i).fishx, bad (i).fishy, bad (i).fishx + 45, bad (i).fishy + 8, 2, 7)
        Draw.ThickLine (bad (i).fishx, bad (i).fishy, bad (i).fishx + 55, bad (i).fishy - 2, 2, 7)
        Draw.ThickLine (bad (i).fishx, bad (i).fishy, bad (i).fishx + 45, bad (i).fishy - 8, 2, 7)
        drawfilloval (bad (i).fishx, bad (i).fishy, bad (i).fishradius, bad (i).fishradius, 56)

        bad (i).fishx -= 1
        if bad (i).fishx < -30 then
            randint (bad (i).fishx, maxx, maxx + 200)
            randint (bad (i).fishy, 30, maxy - 30)
            randint (bad (i).fishradius, 6, 25)
        end if
    end for
end enemies
%%
procedure hit
    drawfilloval (round (xpos), round (ypos), bodyxsize, bodyysize, blue)     %fishs' body
    for i : 1 .. 1
        if Math.Distance (xpos, ypos, bad (i).fishx, bad (i).fishy) < bodyxsize + bad (i).fishradius then
            if bodyxsize >= 30 and bodyysize >= bad (i).fishradius then
                randint (bad (i).fishx, maxx, maxx + 200)
                randint (bad (i).fishy, 30, maxy - 30)
                randint (bad (i).fishradius, 6, 25)
            elsif bodyxsize <= 30 and bodyysize <= bad (i).fishradius then
                die := 1
            end if
        end if
    end for
end hit
%%
loop
    colorback (9)
    cls
    hit
    enemies
    fish
    bubbles
    background
    delay (4)
    View.Update
    if die = 1 then
        cls
        exit
    end if
end loop

Sponsor
Sponsor
Sponsor
sponsor
Remm




PostPosted: Fri Aug 25, 2006 7:49 pm   Post subject: (No subject)

I think its quite nice!

Somthing you might want to change would be being able to go from the top of the screen to the bottom. Fish coming out of the ground.. lol.

Other than that, its great. Have you ever checked out the ! Fishy ! game on newgrounds? Same sort of concept with movement and the likes.

Oh, and also.. when clicking in a direction many times over, you end up having to spam click just to slow yourself down, meaning over time you should be slowing if no keys are being pressed. (so if i stop holding forward, at some point in the future i will stop)
Just somthing to think about, I donno if its reasonable, but its up to you.
pj_ladd12




PostPosted: Sun Aug 27, 2006 9:46 pm   Post subject: (No subject)

i get what you mean, so when yuo let go the fish will gradually slow down and come to stop......lets jsut say the water always keps him moving cuz i dont no how to do that lol
Remm




PostPosted: Wed Aug 30, 2006 8:11 pm   Post subject: (No subject)

the water? er...??
I really cant be of much help around this stuff since I have trouble looking through other peoples code Embarassed

Anyways, family issues on this end, good luck!
Windsurfer




PostPosted: Thu Aug 31, 2006 6:52 pm   Post subject: (No subject)

If you want the fish to slow down, simply divide the speed in the x and y directions by a constant every frame... believe it or not, it will slow it down smoothly. I did that in Forces on the shrapnel and to some extent the enemies.
pj_ladd12




PostPosted: Fri Sep 01, 2006 2:13 pm   Post subject: (No subject)

so i shud make a var for a const, say const: slowdown, wut shud i make it =? 0?
pj_ladd12




PostPosted: Fri Sep 01, 2006 2:21 pm   Post subject: (No subject)

n/m, i got it

xspeed -= 0.01 * sign (xspeed)
King Me




PostPosted: Fri Dec 01, 2006 11:12 am   Post subject: (No subject)

Check out mine Cool Wink


setscreen ("offscreenonly;graphics:530;330;position:100;100;nobuttonbar") %settings
var swim : array char of boolean
var xpos, ypos : real := 200
var bodyxsize : int := 30
var bodyysize : int := 18
var shadowx : real
var shadowxsize : real
var speed : real := 0
var die : int := 0
var sidespeed : real := 0
var bubblex, bubbley, bubbler : array 1 .. 5 of real
var grassx, grassy : array 0 .. 20 of int
shadowxsize := 40
for i : 1 .. 5 %5 random bubbles
bubblex (i) := Rand.Int (round (xpos + 15), round (xpos + 28))
bubbley (i) := Rand.Int (round (ypos - 10), round (ypos + 10))
bubbler (i) := Rand.Int (1, 3)
end for
for i : 0 .. 20
grassx (i) := 0 %weeds
grassy (i) := 0
end for
%%
procedure background
for i : 0 .. 20 %weeds
Draw.ThickLine (grassx (i) + i * 50 + 16, grassy (i) + 40, grassx (i) + i * 50, grassy (i), 3, 190)
Draw.ThickLine (grassx (i) + i * 50 + 10, grassy (i) + 64, grassx (i) + i * 50, grassy (i), 3, green)
Draw.ThickLine (grassx (i) + i * 50 + 20, grassy (i) + 50, grassx (i) + i * 50 + 25, grassy (i), 3, 190)
Draw.ThickLine (grassx (i) + i * 50 + 12, grassy (i) + 40, grassx (i) + i * 50 + 18, grassy (i), 3, 7)
Draw.ThickLine (grassx (i) + i * 50 + 32, grassy (i) + 53, grassx (i) + i * 50 + 28, grassy (i), 3, green)
Draw.ThickLine (grassx (i) + i * 50 + 38, grassy (i) + 40, grassx (i) + i * 50 + 35, grassy (i), 3, 7)
Draw.ThickLine (grassx (i) + i * 50 + 48, grassy (i) + 50, grassx (i) + i * 50 + 35, grassy (i), 3, 190)
Draw.ThickLine (grassx (i) + i * 50 + 48, grassy (i) + 60, grassx (i) + i * 50 + 45, grassy (i), 3, green)
end for
end background
%%
procedure fish
shadowx := xpos %shadow
Input.KeyDown (swim)
drawfilloval (round (xpos), round (ypos), bodyxsize, bodyysize, blue) %fishs' body
drawfilloval (round (xpos + 10), round (ypos + 8), 6, 6, 7)
drawfilloval (round (xpos + 13), round (ypos + 5), 1, 1, 0)
drawfilloval (round (shadowx), 5, round (shadowxsize - 8), bodyysize - 22, 7) %shadow
Draw.ThickLine (round (xpos - 50), round (ypos + 3), round (xpos - bodyxsize), round (ypos), 3, 7) %tail
Draw.ThickLine (round (xpos - 53), round (ypos + 7), round (xpos - bodyxsize), round (ypos + 3), 2, 7)
Draw.ThickLine (round (xpos - 53), round (ypos - 7), round (xpos - bodyxsize), round (ypos - 3), 2, 7)
Draw.ThickLine (round (xpos - 53), round (ypos - 2), round (xpos - bodyxsize), round (ypos - 1), 3, 7)
%controls
if swim (KEY_UP_ARROW) then
speed += 0.01 %speed increase
end if
if swim (KEY_DOWN_ARROW) then
speed -= 0.01 %decrease
end if
if swim (KEY_LEFT_ARROW) then
sidespeed -= 0.01 %""
end if
if swim (KEY_RIGHT_ARROW) then
sidespeed += 0.01 %""
end if
%controls
%speed
xpos += sidespeed %speed
ypos += speed %""
%speed
%boundries
if xpos > maxx + bodyxsize + 24 then
xpos := 0 - bodyxsize %boundries
end if
if xpos < 0 - bodyxsize then
xpos := maxx + bodyxsize + 24
end if
if ypos > maxy + bodyysize then
ypos := 0 - bodyysize
end if
if ypos < 0 - bodyysize then
ypos := maxy + bodyysize
end if
%boundries
%limit speed
if speed > 2 then
speed := 2 %stops at 2
end if
if speed < -2 then
speed := -2
end if
if sidespeed > 2 then
sidespeed := 2
end if
if sidespeed < -2 then
sidespeed := -2
end if
%limit speed
%shadow settings
if speed >= 0.1 then
shadowxsize += 0.1 %shadow increases if fish swims upward
elsif speed <= -0.1 then
shadowxsize -= 0.1
end if
if ypos >= maxy + bodyysize then %fish is at top
shadowxsize := 40
end if
if ypos <= 0 - bodyysize then %fish is at bottom
shadowxsize := 40
end if
%shadow settings
end fish
%%
procedure bubbles
for i : 1 .. 5
drawoval (round (bubblex (i)), round (bubbley (i)), round (bubbler (i)), round (bubbler (i)), 8)
bubbley (i) += .1 %speed
if bubbley (i) > maxy + 10 then %if get to top
bubblex (i) := Rand.Int (round (xpos + 15), round (xpos + 28))
bubbley (i) := Rand.Int (round (ypos - 10), round (ypos + 10))
bubbler (i) := Rand.Int (1, 3)
end if
end for
end bubbles
%%
type otherfish :
record
fishx : int
fishy : int
fishradius : int
end record
var bad : array 1 .. 6 of otherfish
for i : 1 .. 6
randint (bad (i).fishx, maxx, maxx + 200)
randint (bad (i).fishy, 30, maxy - 30)
randint (bad (i).fishradius, 6, 25)
end for
procedure enemies
for i : 1 .. 6
Draw.ThickLine (bad (i).fishx, bad (i).fishy, bad (i).fishx + 55, bad (i).fishy + 6, 2, 7)
Draw.ThickLine (bad (i).fishx, bad (i).fishy, bad (i).fishx + 45, bad (i).fishy + 8, 2, 7)
Draw.ThickLine (bad (i).fishx, bad (i).fishy, bad (i).fishx + 55, bad (i).fishy - 2, 2, 7)
Draw.ThickLine (bad (i).fishx, bad (i).fishy, bad (i).fishx + 45, bad (i).fishy - 8, 2, 7)
drawfilloval (bad (i).fishx, bad (i).fishy, bad (i).fishradius, bad (i).fishradius, 56)

bad (i).fishx -= 1
if bad (i).fishx < -30 then
randint (bad (i).fishx, maxx, maxx + 200)
randint (bad (i).fishy, 30, maxy - 30)
randint (bad (i).fishradius, 6, 25)
end if
end for
end enemies
%%
procedure hit
drawfilloval (round (xpos), round (ypos), bodyxsize, bodyysize, blue) %fishs' body
for i : 1 .. 1
if Math.Distance (xpos, ypos, bad (i).fishx, bad (i).fishy) < bodyxsize + bad (i).fishradius then
if bodyxsize >= 30 and bodyysize >= bad (i).fishradius then
randint (bad (i).fishx, maxx, maxx + 200)
randint (bad (i).fishy, 30, maxy - 30)
randint (bad (i).fishradius, 6, 25)
elsif bodyxsize <= 30 and bodyysize <= bad (i).fishradius then
die := 1
end if
end if
end for
end hit
%%
loop
colorback (9)
cls
hit
enemies
fish
bubbles
background
delay (4)
View.Update
if die = 1 then
cls
exit
end if
end loop

const tempo := 100 %Tempo is at a quarter base
%Note-Duration (or rests)
%Normal-Notes
const w := round (2000 * (120 / tempo)) %Whole notes
const h := round (1000 * (120 / tempo)) %Half Notes
const q := round (500 * (120 / tempo)) %Quarter Notes
const e := round (250 * (120 / tempo)) %Eighth Notes
const s := round (125 * (120 / tempo)) %Sixteenth Notes
%Dotted-Notes
const w_dot := round (w * 1.5)
const h_dot := round (h * 1.5)
const q_dot := round (q * 1.5)
const e_dot := round (e * 1.5)
const s_dot := round (s * 1.5)
%Triplet-Notes
const w3 := round (w * 2 / 3)
const h3 := round (h * 2 / 3)
const q3 := round (q * 2 / 3)
const e3 := round (e * 2 / 3)
const s3 := round (s * 2 / 3)
%Notes
const G := 196
const Gs := 207
const Ab := 207
const A := 220
const As := 233
const Bb := 233
const B := 247
const C := 261
const Cs := 277
const Db := 277
const D := 293
const Ds := 311
const Eb := 311
const E := 329
const F := 349
const Fs := 370
const Gb := 370
%To raise it by an octave, times it by 2
%To lower it by an octave, divide it by 2
%Mario

for i : 1 .. 2
Music.Sound (C div 2, s)
Music.Sound (E div 2, s)
Music.Sound (G, s)
Music.Sound (C, s)

Music.Sound (E, s)
Music.Sound (G, s)
Music.Sound (C, s)
Music.Sound (E, s)
end for
for i : 1 .. 2
Music.Sound (C div 2, s)
Music.Sound (D div 2, s)
Music.Sound (A, s)
Music.Sound (D, s)

Music.Sound (F, s)
Music.Sound (A, s)
Music.Sound (D, s)
Music.Sound (F, s)
end for
for i : 1 .. 2
Music.Sound (B div 2, s)
Music.Sound (D div 2, s)
Music.Sound (G, s)
Music.Sound (D, s)

Music.Sound (F, s)
Music.Sound (G, s)
Music.Sound (D, s)
Music.Sound (F, s)
end for
for i : 1 .. 2
Music.Sound (C div 2, s)
Music.Sound (E div 2, s)
Music.Sound (G, s)
Music.Sound (C, s)

Music.Sound (E, s)
Music.Sound (G, s)
Music.Sound (C, s)
Music.Sound (E, s)
end for


Cool
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: