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

Username:   Password: 
 RegisterRegister   
 general advice
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
MyPistolsIn3D




PostPosted: Thu Apr 29, 2004 12:12 pm   Post subject: general advice

Hey, I am making an asteroids type game for my FP cept with planes, and I am doing it with classes. Any advice that anyone has to make it run smoothly and nicely would be very much appreciated.
The class:
Quote:
%File "planeCl.tu"
unit
class PlaneCl
export SetPosition, TurnRight, TurnLeft, Move
var angle := 90
var x, y : int
var key : string (1)
Draw.FillOval (100, 104, 18, 5, black) %tail
Draw.FillBox (94, 100, 106, 150, black) %body
Draw.FillOval (100, 150, 6, 10, black) %nose
Draw.FillOval (100, 135, 50, 8, black) %wing
Draw.FillBox (77, 139, 80, 150, black) %left gun
Draw.FillBox (120, 139, 123, 150, black) %right gun
var picID := Pic.New (50, 50, 150, 170)

proc SetPosition (newX, newY : int)
x := newX
y := newY
end SetPosition

proc TurnRight (turnAngle : int)
angle -= turnAngle
angle := angle mod 360
end TurnRight

proc TurnLeft (turnAngle : int)
angle += turnAngle
angle := angle mod 360
end TurnLeft

proc Move (x, y : int)
cls
Pic.Draw (picID, x, y, picMerge)
end Move

end PlaneCl


The run prog.:

Quote:
import PlaneCl in "planecl.tu"
View.Set ("graphics:600;400,nocursor,offscreenonly")
var x, y : int := 1
var button : int
var yb : int := 400
var fireclr, q : int
var guny : int
var key : string (1)
var plane : ^PlaneCl
new plane

plane -> SetPosition (100, 100)
Draw.FillOval (400, 40, 2, 15, brightred)
Draw.FillBox (398, 10, 402, 40, black)
Draw.Line (397, 25, 391, 10, 2)
Draw.Line (391, 10, 398, 10, 2)
Draw.Line (403, 25, 409, 10, 2)
Draw.Line (409, 10, 402, 10, 2)
var picID := Pic.New (390, 2, 409, 55)
process gunfire
guny := y + 50
for fire : x .. maxx
q := Rand.Int (1, 2)
if q = 1 then
fireclr := 43
elsif q = 2 then
fireclr := yellow
end if
Draw.FillOval (x - 25, guny, 2, 2, fireclr)
Draw.FillOval (x + 22, guny, 2, 2, fireclr)
guny += 3
end for
end gunfire
process rocketfire
guny := y + 50
for fire : x .. maxx
Pic.Draw (picID, x-10, guny, picCopy)
delay (100)
guny += 3
end for
end rocketfire
loop
Mouse.Where (x, y, button)
plane -> Move (x - 50, y - 60)
if button = 1 then
fork rocketfire
end if
View.Update
end loop
Sponsor
Sponsor
Sponsor
sponsor
MyPistolsIn3D




PostPosted: Thu Apr 29, 2004 12:48 pm   Post subject: more

Well, what i really need is how to get enemy planes flying from top to bottom of the screen at the same time i move my plane(ill do collision detection and crap later).thx.
Delta




PostPosted: Thu Apr 29, 2004 1:04 pm   Post subject: (No subject)

Ok first off you have a huge problem... you may not have noticed it... but try holdingdown the mouse button... you'll see what I mean. And as for moving the planes down (top to bottom)... try something like this

code:
View.Set ("offscreenonly")

type planes :
    record
        x : int
        y : int
    end record

var plane : array 1 .. 10 of planes

for i : 1 .. 10
    plane(i).x := Rand.Int (0, maxx)
    plane(i).y := Rand.Int (maxy, maxy + 800)
end for

loop
    cls
    for i : 1 .. 10
        plane (i).y -= 5
        Draw.FillOval (plane(i).x, plane(i).y, 10, 10, 2)
    end for
    delay (100)
    View.Update
end loop
MyPistolsIn3D




PostPosted: Thu Apr 29, 2004 1:29 pm   Post subject: (No subject)

Thx man, any advice for how to make the shooting more smooth? Ive tried everything and it always looks kinda gay. And how would i change the green dots into pics? the "type" thingy confuses me.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: