3d version of my 2d space game(incomplete)
Author |
Message |
Homer_simpson
|
Posted: Sat Jan 10, 2009 2:17 am Post subject: 3d version of my 2d space game(incomplete) |
|
|
it's still not finished
controls are :
arrow keys to change direction
w speed up
s slow down
a,d are strafe buttons
for now all you can do is chase the other ship in 3d space but i'll update it soon
Description: |
|
Download |
Filename: |
ship.zip |
Filesize: |
283.19 KB |
Downloaded: |
128 Time(s) |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Homer_simpson
|
Posted: Sat Jan 10, 2009 6:44 pm Post subject: Re: 3d version of my 2d space game(incomplete) |
|
|
i realized that in turing this will turn up really slow so i'll remake this in c++
here's version with more airplane like controls
Description: |
|
Download |
Filename: |
box.zip |
Filesize: |
281.04 KB |
Downloaded: |
115 Time(s) |
|
|
|
|
|
|
saltpro15
|
Posted: Sat Jan 10, 2009 7:25 pm Post subject: Re: 3d version of my 2d space game(incomplete) |
|
|
well, that just made my day. Can I have a hint as to how you made it? I'd like to do something like this for my final project
|
|
|
|
|
|
Zren
|
Posted: Mon Jan 12, 2009 2:34 am Post subject: Re: 3d version of my 2d space game(incomplete) |
|
|
Funky, but what's the point of the game (not that flying around in space isn't awesome)?
|
|
|
|
|
|
Homer_simpson
|
Posted: Mon Jan 12, 2009 9:19 pm Post subject: Re: 3d version of my 2d space game(incomplete) |
|
|
well i was going to make it a dogfight style game but turing is very slow with graphics specially 3d graphics so i decided to make it with c++, but here's the code if any1's interested :
Quote:
class Homer3Dengine
export loadarf, loadraw, moveobject, drawobject, camera, obj, movecamera, vector
type dot :
record
x, y, z : real
end record
proc assign3d (var d : dot, x, y, z : real)
d.x := x
d.y := y
d.z := z + 10
end assign3d
type object :
record
axy, axz, ayz, cx, cy, cz : real
maxpoly : int
poly : array 1 .. 1000, 1 .. 3 of dot
col : array 1 .. 1000 of int
end record
var obj : object
var vector : dot
type cam :
record
axy, axz, ayz, cx, cy, cz, zoom : real
end record
var camera : cam
camera.cx := 0
camera.cy := 0
camera.cz := 0
camera.axy := 0
camera.axz := 0
camera.ayz := 0
camera.zoom := 300
proc loadarf (filename : string)
var file, i : int := 0
var x1, y1, z1, x2, y2, z2, x3, y3, z3 : real
var col : int
vector.x := 0
vector.y := 0
vector.z := -1
open : file, filename, read
loop
exit when eof (file)
i += 1
read : file, x1, y1, z1, x2, y2, z2, x3, y3, z3, col
assign3d (obj.poly (i, 1), x1, y1, z1)
assign3d (obj.poly (i, 2), x2, y2, z2)
assign3d (obj.poly (i, 3), x3, y3, z3)
obj.col (i) := col
end loop
obj.maxpoly := i
/* for i2 : 1 .. obj.maxpoly
for ii : 1 .. 3
obj.poly (i2, ii).z += 200
end for
end for*/
obj.axy := 0
obj.axz := 0
obj.ayz := 0
end loadarf
proc loadraw (filename : string, lines : int)
var file : int
var x1, y1, z1, x2, y2, z2, x3, y3, z3 : real
open : file, filename, get
obj.maxpoly := lines
for i : 1 .. lines
get : file, x1, y1, z1, x2, y2, z2, x3, y3, z3
assign3d (obj.poly (i, 1), x1, y1, z1)
assign3d (obj.poly (i, 2), x2, y2, z2)
assign3d (obj.poly (i, 3), x3, y3, z3)
end for
for i : 1 .. obj.maxpoly
for ii : 1 .. 3
obj.poly (i, ii).z += 200
end for
end for
obj.axy := 0
obj.axz := 0
obj.ayz := 0
end loadraw
proc rotate (OriginX, OriginY : real, var secondpartX, secondpartY : real, Rotaion : real)
var tempx := (((OriginX - secondpartX) * cosd (Rotaion)) + ((OriginY - secondpartY) * sind (Rotaion)))
var tempy := (((OriginY - secondpartY) * cosd (Rotaion)) - ((OriginX - secondpartX) * sind (Rotaion)))
secondpartY := OriginY - tempy
secondpartX := OriginX - tempx
end rotate
proc findcenter (var x, y, z : real)
x := 0.0
y := 0.0
z := 0.0
for i : 1 .. obj.maxpoly
for ii : 1 .. 3
x += obj.poly (i, ii).x
y += obj.poly (i, ii).y
z += obj.poly (i, ii).z
end for
end for
x /= (obj.maxpoly * 3)
y /= (obj.maxpoly * 3)
z /= (obj.maxpoly * 3)
%drawfilloval (round (obj.cx / (obj.cz / camera.zoom)) + 320, round (obj.cy / (obj.cz / camera.zoom)) + 200, 10, 10, 12)
end findcenter
proc draw3ddot (d1, d2, d3 : dot, c, c2 : int, filled : boolean)
if d1.z not= 0 and d2.z not= 0 and d3.z not= 0 then
% drawline (round (d1.x / (d1.z / camera.zoom)) + 320, round (d1.y / (d1.z / camera.zoom)) + 200, round (d2.x / (d2.z / camera.zoom)) + 320, round (d2.y / (d2.z / camera.zoom)) + 200, c)
% drawline (round (d1.x / (d1.z / camera.zoom)) + 320, round (d1.y / (d1.z / camera.zoom)) + 200, round (d3.x / (d3.z / camera.zoom)) + 320, round (d3.y / (d3.z / camera.zoom)) + 200, c)
% drawline (round (d2.x / (d2.z / camera.zoom)) + 320, round (d2.y / (d2.z / camera.zoom)) + 200, round (d3.x / (d3.z / camera.zoom)) + 320, round (d3.y / (d3.z / camera.zoom)) + 200, c)
%drawline (round (obj.cx / (obj.cz / camera.zoom)) + 320, round (obj.cy / (obj.cz / camera.zoom)) + 200, round (d2.x / (d2.z / camera.zoom)) + 320, round (d2.y / (d2.z / camera.zoom)) + 200, 12)
var xx : array 1 .. 3 of int
var yy : array 1 .. 3 of int
xx (1) := round ((d1.x - camera.cx) / ((d1.z - camera.cz) / camera.zoom)) + 320
xx (2) := round ((d2.x - camera.cx) / ((d2.z - camera.cz) / camera.zoom)) + 320
xx (3) := round ((d3.x - camera.cx) / ((d3.z - camera.cz) / camera.zoom)) + 320
yy (1) := round ((d1.y - camera.cy) / ((d1.z - camera.cz) / camera.zoom)) + 200
yy (2) := round ((d2.y - camera.cy) / ((d2.z - camera.cz) / camera.zoom)) + 200
yy (3) := round ((d3.y - camera.cy) / ((d3.z - camera.cz) / camera.zoom)) + 200
Draw.Dot (xx (1), yy (1), white)
Draw.Dot (xx (2), yy (2), white)
Draw.Dot (xx (3), yy (3), white)
end if
end draw3ddot
proc draw3dpolygon (d1, d2, d3 : dot, c, c2 : int, filled : boolean)
var draw := false
if d1.z not= 0 and d2.z not= 0 and d3.z not= 0 then
% drawline (round (d1.x / (d1.z / camera.zoom)) + 320, round (d1.y / (d1.z / camera.zoom)) + 200, round (d2.x / (d2.z / camera.zoom)) + 320, round (d2.y / (d2.z / camera.zoom)) + 200, c)
% drawline (round (d1.x / (d1.z / camera.zoom)) + 320, round (d1.y / (d1.z / camera.zoom)) + 200, round (d3.x / (d3.z / camera.zoom)) + 320, round (d3.y / (d3.z / camera.zoom)) + 200, c)
% drawline (round (d2.x / (d2.z / camera.zoom)) + 320, round (d2.y / (d2.z / camera.zoom)) + 200, round (d3.x / (d3.z / camera.zoom)) + 320, round (d3.y / (d3.z / camera.zoom)) + 200, c)
%drawline (round (obj.cx / (obj.cz / camera.zoom)) + 320, round (obj.cy / (obj.cz / camera.zoom)) + 200, round (d2.x / (d2.z / camera.zoom)) + 320, round (d2.y / (d2.z / camera.zoom)) + 200, 12)
var xx : array 1 .. 3 of int
var yy : array 1 .. 3 of int
if d1.z not= camera.cz and d2.z not= camera.cz and d3.z not= camera.cz and d1.z > camera.cz and d2.z > camera.cz and d3.z > camera.cz then
xx (1) := round ((d1.x - camera.cx) / ((d1.z - camera.cz) / camera.zoom)) + 320
xx (2) := round ((d2.x - camera.cx) / ((d2.z - camera.cz) / camera.zoom)) + 320
xx (3) := round ((d3.x - camera.cx) / ((d3.z - camera.cz) / camera.zoom)) + 320
yy (1) := round ((d1.y - camera.cy) / ((d1.z - camera.cz) / camera.zoom)) + 200
yy (2) := round ((d2.y - camera.cy) / ((d2.z - camera.cz) / camera.zoom)) + 200
yy (3) := round ((d3.y - camera.cy) / ((d3.z - camera.cz) / camera.zoom)) + 200
for ii : 1 .. 3
if xx (ii) > 0 and xx (ii) < maxx and yy (ii) > 0 and yy (ii) < maxy then
draw := true
else
draw := false
end if
end for
if draw then
if filled then
Draw.FillPolygon (xx, yy, 3, c)
end if
Draw.Polygon (xx, yy, 3, c2)
end if
end if
end if
end draw3dpolygon
proc drawobject (col, col2, typ : int)
if typ = 1 then
for i : 1 .. obj.maxpoly
draw3dpolygon (obj.poly (i, 1), obj.poly (i, 2), obj.poly (i, 3), col, col2, true)
end for
end if
if typ = 2 then
var cc : real
for i : 1 .. obj.maxpoly
cc := (obj.poly (i, 2).z + obj.poly (i, 1).z + obj.poly (i, 3).z) / 3
draw3dpolygon (obj.poly (i, 1), obj.poly (i, 2), obj.poly (i, 3), (16 + (14 - (round ((cc / 31) mod 14)))), col2, true)
end for
end if
if typ = 3 then
for i : 1 .. obj.maxpoly
draw3dpolygon (obj.poly (i, 1), obj.poly (i, 2), obj.poly (i, 3), col, col2, false)
end for
end if
if typ = 4 then
for i : 1 .. obj.maxpoly
draw3dpolygon (obj.poly (i, 1), obj.poly (i, 2), obj.poly (i, 3), obj.col (i), col2, true)
end for
end if
if typ = 5 then
var cc : real
for i : 1 .. obj.maxpoly
cc := (obj.poly (i, 2).z + obj.poly (i, 1).z + obj.poly (i, 3).z) / 3
draw3ddot (obj.poly (i, 1), obj.poly (i, 2), obj.poly (i, 3), (16 + (14 - (round ((cc / 31) mod 14)))), col2, false)
end for
end if
end drawobject
proc moveobject (s : string, d : real)
findcenter (obj.cx, obj.cy, obj.cz)
case s of
label "xy" :
obj.axy += d
rotate (0, 0, vector.x, vector.y, d)
for i : 1 .. obj.maxpoly
for ii : 1 .. 3
rotate (obj.cx, obj.cy, obj.poly (i, ii).x, obj.poly (i, ii).y, d)
end for
end for
label "xz" :
rotate (0, 0, vector.x, vector.z, d)
obj.axz += d
for i : 1 .. obj.maxpoly
for ii : 1 .. 3
rotate (obj.cx, obj.cz, obj.poly (i, ii).x, obj.poly (i, ii).z, d)
end for
end for
label "yz" :
rotate (0, 0, vector.y, vector.z, d)
obj.ayz += d
for i : 1 .. obj.maxpoly
for ii : 1 .. 3
rotate (obj.cy, obj.cz, obj.poly (i, ii).y, obj.poly (i, ii).z, d)
end for
end for
label "x" :
for i : 1 .. obj.maxpoly
for ii : 1 .. 3
obj.poly (i, ii).x += d
end for
end for
label "y" :
for i : 1 .. obj.maxpoly
for ii : 1 .. 3
obj.poly (i, ii).y += d
end for
end for
label "z" :
for i : 1 .. obj.maxpoly
for ii : 1 .. 3
obj.poly (i, ii).z += d
end for
end for
label :
end case
end moveobject
proc movecamera (s : string, d : real)
findcenter (obj.cx, obj.cy, obj.cz)
var dis := sqrt (((camera.cx - obj.cx) ** 2) + ((camera.cz - obj.cz) ** 2))
case s of
label "xy" :
camera.axy += d
rotate (0, 0, vector.x, vector.y, d)
for i : 1 .. obj.maxpoly
for ii : 1 .. 3
rotate (camera.cx, camera.cy, obj.poly (i, ii).x, obj.poly (i, ii).y, d)
end for
end for
label "xz" :
%vector.x += camera.cx - obj.cx
%vector.z += camera.cz - obj.cz
rotate (0, 0, vector.x, vector.z, d)
%vector.x -= sind (d) * dis
%vector.z -= cosd (d) * dis
camera.axz += d
for i : 1 .. obj.maxpoly
for ii : 1 .. 3
rotate (camera.cx, camera.cz, obj.poly (i, ii).x, obj.poly (i, ii).z, d)
%rotate (camera.cx, camera.cz, vector.x, vector.z, d)
end for
end for
label "yz" :
camera.ayz += d
rotate (0, 0, vector.y, vector.z, d)
for i : 1 .. obj.maxpoly
for ii : 1 .. 3
rotate (camera.cy, camera.cz, obj.poly (i, ii).y, obj.poly (i, ii).z, d)
%rotate (camera.cy, camera.cz, vector.y, vector.z, d)
end for
end for
label "x" :
camera.cx += d
label "y" :
camera.cy += d
label "z" :
camera.cz += d
label "zoom" :
camera.zoom += d
if camera.zoom = 0 then
camera.zoom += d
end if
label :
end case
end movecamera
end Homer3Dengine
class MainEngine
export InitiateStars, loadraw, moveobject, drawobject, camera, obj, movecamera
const MaxStars := 5
type dot :
record
x, y, z : real
end record
proc assign3d (var d : dot, x, y, z : real)
d.x := x
d.y := y
d.z := z + 10
end assign3d
type object :
record
axy, axz, ayz, cx, cy, cz : real
maxpoly : int
poly : array 1 .. 1000, 1 .. 3 of dot
col : array 1 .. 1000 of int
end record
var obj : object
type cam :
record
axy, axz, ayz, cx, cy, cz, zoom : real
end record
var camera : cam
camera.cx := 0
camera.cy := 0
camera.cz := 0
camera.axy := 0
camera.axz := 0
camera.ayz := 0
camera.zoom := 300
proc InitiateStars ()
var x1, y1, z1, x2, y2, z2, x3, y3, z3 : real
var col : int
for i : 1 .. MaxStars
for ii : 1 .. 3
assign3d (obj.poly (i, ii), Rand.Int (-5000, 5000), Rand.Int (-5000, 5000), Rand.Int (50, 5000))
end for
obj.col (i) := 0
obj.maxpoly := i
end for
for i2 : 1 .. obj.maxpoly
for ii : 1 .. 3
obj.poly (i2, ii).z += 200
end for
end for
obj.axy := 0
obj.axz := 0
obj.ayz := 0
end InitiateStars
proc loadraw (filename : string, lines : int)
var file : int
var x1, y1, z1, x2, y2, z2, x3, y3, z3 : real
open : file, filename, get
obj.maxpoly := lines
for i : 1 .. lines
get : file, x1, y1, z1, x2, y2, z2, x3, y3, z3
assign3d (obj.poly (i, 1), x1, y1, z1)
assign3d (obj.poly (i, 2), x2, y2, z2)
assign3d (obj.poly (i, 3), x3, y3, z3)
end for
for i : 1 .. obj.maxpoly
for ii : 1 .. 3
obj.poly (i, ii).z += 200
end for
end for
obj.axy := 0
obj.axz := 0
obj.ayz := 0
end loadraw
proc rotate (OriginX, OriginY : real, var secondpartX, secondpartY : real, Rotaion : real)
var tempx := (((OriginX - secondpartX) * cosd (Rotaion)) + ((OriginY - secondpartY) * sind (Rotaion)))
var tempy := (((OriginY - secondpartY) * cosd (Rotaion)) - ((OriginX - secondpartX) * sind (Rotaion)))
secondpartY := OriginY - tempy
secondpartX := OriginX - tempx
end rotate
proc findcenter (var x, y, z : real)
x := 0.0
y := 0.0
z := 0.0
for i : 1 .. obj.maxpoly
for ii : 1 .. 3
x += obj.poly (i, ii).x
y += obj.poly (i, ii).y
z += obj.poly (i, ii).z
end for
end for
x /= (obj.maxpoly * 3)
y /= (obj.maxpoly * 3)
z /= (obj.maxpoly * 3)
%drawfilloval (round (obj.cx / (obj.cz / camera.zoom)) + 320, round (obj.cy / (obj.cz / camera.zoom)) + 200, 10, 10, 12)
end findcenter
proc draw3ddot (d1, d2, d3 : dot, c, c2 : int, filled : boolean, i : int)
if d1.z not= 0 and d2.z not= 0 and d3.z not= 0 then
% drawline (round (d1.x / (d1.z / camera.zoom)) + 320, round (d1.y / (d1.z / camera.zoom)) + 200, round (d2.x / (d2.z / camera.zoom)) + 320, round (d2.y / (d2.z / camera.zoom)) + 200, c)
% drawline (round (d1.x / (d1.z / camera.zoom)) + 320, round (d1.y / (d1.z / camera.zoom)) + 200, round (d3.x / (d3.z / camera.zoom)) + 320, round (d3.y / (d3.z / camera.zoom)) + 200, c)
% drawline (round (d2.x / (d2.z / camera.zoom)) + 320, round (d2.y / (d2.z / camera.zoom)) + 200, round (d3.x / (d3.z / camera.zoom)) + 320, round (d3.y / (d3.z / camera.zoom)) + 200, c)
%drawline (round (obj.cx / (obj.cz / camera.zoom)) + 320, round (obj.cy / (obj.cz / camera.zoom)) + 200, round (d2.x / (d2.z / camera.zoom)) + 320, round (d2.y / (d2.z / camera.zoom)) + 200, 12)
var xx : array 1 .. 3 of int
var yy : array 1 .. 3 of int
if d1.z not= camera.cz and d2.z not= camera.cz and d3.z not= camera.cz and d1.z > camera.cz and d2.z > camera.cz and d3.z > camera.cz then
xx (1) := round ((d1.x - camera.cx) / ((d1.z - camera.cz) / camera.zoom)) + 320
xx (2) := round ((d2.x - camera.cx) / ((d2.z - camera.cz) / camera.zoom)) + 320
xx (3) := round ((d3.x - camera.cx) / ((d3.z - camera.cz) / camera.zoom)) + 320
yy (1) := round ((d1.y - camera.cy) / ((d1.z - camera.cz) / camera.zoom)) + 200
yy (2) := round ((d2.y - camera.cy) / ((d2.z - camera.cz) / camera.zoom)) + 200
yy (3) := round ((d3.y - camera.cy) / ((d3.z - camera.cz) / camera.zoom)) + 200
for ii : 1 .. 3
if xx (ii) > 0 and xx (ii) < maxx and yy (ii) > 0 and yy (ii) < maxy then
Draw.Dot (xx (ii), yy (ii), white)
else
assign3d (obj.poly (i, ii), camera.cx + Rand.Int (-4500, 4500), camera.cy + Rand.Int (-2500, 2500), camera.cz + Rand.Int (4000, 5000))
end if
end for
end if
end if
end draw3ddot
proc draw3dpolygon (d1, d2, d3 : dot, c, c2 : int, filled : boolean)
if d1.z not= 0 and d2.z not= 0 and d3.z not= 0 then
% drawline (round (d1.x / (d1.z / camera.zoom)) + 320, round (d1.y / (d1.z / camera.zoom)) + 200, round (d2.x / (d2.z / camera.zoom)) + 320, round (d2.y / (d2.z / camera.zoom)) + 200, c)
% drawline (round (d1.x / (d1.z / camera.zoom)) + 320, round (d1.y / (d1.z / camera.zoom)) + 200, round (d3.x / (d3.z / camera.zoom)) + 320, round (d3.y / (d3.z / camera.zoom)) + 200, c)
% drawline (round (d2.x / (d2.z / camera.zoom)) + 320, round (d2.y / (d2.z / camera.zoom)) + 200, round (d3.x / (d3.z / camera.zoom)) + 320, round (d3.y / (d3.z / camera.zoom)) + 200, c)
%drawline (round (obj.cx / (obj.cz / camera.zoom)) + 320, round (obj.cy / (obj.cz / camera.zoom)) + 200, round (d2.x / (d2.z / camera.zoom)) + 320, round (d2.y / (d2.z / camera.zoom)) + 200, 12)
var xx : array 1 .. 3 of int
var yy : array 1 .. 3 of int
xx (1) := round ((d1.x - camera.cx) / ((d1.z - camera.cz) / camera.zoom)) + 320
xx (2) := round ((d2.x - camera.cx) / ((d2.z - camera.cz) / camera.zoom)) + 320
xx (3) := round ((d3.x - camera.cx) / ((d3.z - camera.cz) / camera.zoom)) + 320
yy (1) := round ((d1.y - camera.cy) / ((d1.z - camera.cz) / camera.zoom)) + 200
yy (2) := round ((d2.y - camera.cy) / ((d2.z - camera.cz) / camera.zoom)) + 200
yy (3) := round ((d3.y - camera.cy) / ((d3.z - camera.cz) / camera.zoom)) + 200
if filled then
Draw.FillPolygon (xx, yy, 3, c)
end if
Draw.Polygon (xx, yy, 3, c2)
end if
end draw3dpolygon
proc drawobject (col, col2, typ : int)
if typ = 1 then
for i : 1 .. obj.maxpoly
draw3dpolygon (obj.poly (i, 1), obj.poly (i, 2), obj.poly (i, 3), col, col2, true)
end for
end if
if typ = 2 then
var cc : real
for i : 1 .. obj.maxpoly
cc := (obj.poly (i, 2).z + obj.poly (i, 1).z + obj.poly (i, 3).z) / 3
draw3dpolygon (obj.poly (i, 1), obj.poly (i, 2), obj.poly (i, 3), (16 + (14 - (round ((cc / 31) mod 14)))), col2, true)
end for
end if
if typ = 3 then
for i : 1 .. obj.maxpoly
draw3dpolygon (obj.poly (i, 1), obj.poly (i, 2), obj.poly (i, 3), col, col2, false)
end for
end if
if typ = 4 then
for i : 1 .. obj.maxpoly
draw3dpolygon (obj.poly (i, 1), obj.poly (i, 2), obj.poly (i, 3), obj.col (i), col2, true)
end for
end if
if typ = 5 then
var cc : real
for i : 1 .. obj.maxpoly
cc := (obj.poly (i, 2).z + obj.poly (i, 1).z + obj.poly (i, 3).z) / 3
draw3ddot (obj.poly (i, 1), obj.poly (i, 2), obj.poly (i, 3), (16 + (14 - (round ((cc / 31) mod 14)))), col2, false, i)
end for
end if
end drawobject
proc moveobject (s : string, d : real)
findcenter (obj.cx, obj.cy, obj.cz)
case s of
label "xy" :
obj.axy += d
for i : 1 .. obj.maxpoly
for ii : 1 .. 3
rotate (obj.cx, obj.cy, obj.poly (i, ii).x, obj.poly (i, ii).y, d)
end for
end for
label "xz" :
obj.axz += d
for i : 1 .. obj.maxpoly
for ii : 1 .. 3
rotate (obj.cx, obj.cz, obj.poly (i, ii).x, obj.poly (i, ii).z, d)
end for
end for
label "yz" :
obj.ayz += d
for i : 1 .. obj.maxpoly
for ii : 1 .. 3
rotate (obj.cy, obj.cz, obj.poly (i, ii).y, obj.poly (i, ii).z, d)
end for
end for
label "x" :
for i : 1 .. obj.maxpoly
for ii : 1 .. 3
obj.poly (i, ii).x += d
end for
end for
label "y" :
for i : 1 .. obj.maxpoly
for ii : 1 .. 3
obj.poly (i, ii).y += d
end for
end for
label "z" :
for i : 1 .. obj.maxpoly
for ii : 1 .. 3
obj.poly (i, ii).z += d
end for
end for
label :
end case
end moveobject
proc movecamera (s : string, d : real)
case s of
label "xy" :
camera.axy += d
for i : 1 .. obj.maxpoly
for ii : 1 .. 3
rotate (camera.cx, camera.cy, obj.poly (i, ii).x, obj.poly (i, ii).y, d)
end for
end for
label "xz" :
camera.axz += d
for i : 1 .. obj.maxpoly
for ii : 1 .. 3
rotate (camera.cx, camera.cz, obj.poly (i, ii).x, obj.poly (i, ii).z, d)
end for
end for
label "yz" :
camera.ayz += d
for i : 1 .. obj.maxpoly
for ii : 1 .. 3
rotate (camera.cy, camera.cz, obj.poly (i, ii).y, obj.poly (i, ii).z, d)
end for
end for
label "x" :
camera.cx += d
label "y" :
camera.cy += d
label "z" :
camera.cz += d
label "zoom" :
camera.zoom += d
if camera.zoom = 0 then
camera.zoom += d
end if
label :
end case
end movecamera
end MainEngine
const maxenemy := 10
var chars : array char of boolean
var main : ^MainEngine
var spike : array 1 .. maxenemy of ^Homer3Dengine
for i : 1 .. maxenemy
new Homer3Dengine, spike (i)
spike (i) -> loadarf ("box.arf")
spike (i) -> moveobject ("z", Rand.Int (5000, 10000))
spike (i) -> moveobject ("x", Rand.Int (-500, 500))
spike (i) -> moveobject ("y", Rand.Int (-500, 500))
spike (i) -> moveobject ("yz", Rand.Int (0, 360))
spike (i) -> moveobject ("xz", Rand.Int (0, 360))
spike (i) -> moveobject ("xy", Rand.Int (0, 360))
end for
new MainEngine, main
main -> InitiateStars
colorback (black)
cls
View.Set ("offscreenonly")
color (white)
var velocity : real := 40
var tvelocityx, tvelocityy : real := 0
loop
Input.KeyDown (chars)
if chars (KEY_LEFT_ARROW) then
if tvelocityx < 4 then
tvelocityx += .4
end if
end if
if chars (KEY_RIGHT_ARROW) then
if tvelocityx > -4 then
tvelocityx -= .4
end if
end if
if chars (KEY_UP_ARROW) then
if tvelocityy < 4 then
tvelocityy += .4
end if
end if
if chars (KEY_DOWN_ARROW) then
if tvelocityx > -4 then
tvelocityy -= .4
end if
end if
if chars ('a') then
for i : 1 .. maxenemy
spike (i) -> movecamera ("x", -100) %moves camera in z axis
end for
main -> movecamera ("x", -100) %moves camera in z axis
end if
if chars ('d') then
for i : 1 .. maxenemy
spike (i) -> movecamera ("x", 100) %moves camera in z axis
end for
main -> movecamera ("x", 100) %moves camera in z axis
end if
if chars ('w') then
if velocity < 150 then
velocity += 4
end if
end if
if chars ('s') then
if velocity > 10 then
velocity -= 10
end if
end if
for i : 1 .. maxenemy
end for
for i : 1 .. maxenemy
spike (i) -> moveobject ("xz", 1)
spike (i) -> moveobject ("yz", 1)
spike (i) -> moveobject ("x", (spike (i) -> vector.x * 50)) %moves camera in z axis
spike (i) -> moveobject ("z", (spike (i) -> vector.z * 50)) %moves camera in z axis
spike (i) -> moveobject ("y", (spike (i) -> vector.y * 50)) %moves camera in z axis
%spike (i) -> moveobject ("z", cosd (spike (i) -> obj.ayz) * 50) %moves camera in z axis
spike (i) -> movecamera ("z", velocity) %moves camera in z axis
if tvelocityx not= 0 then
spike (i) -> movecamera ("xy", tvelocityx) %moves camera in z axis
end if
if tvelocityy not= 0 then
spike (i) -> movecamera ("yz", tvelocityy) %moves camera in z axis
end if
end for
main -> movecamera ("z", velocity) %moves camera in z axis
if tvelocityy not= 0 then
main -> movecamera ("yz", tvelocityy) %moves camera in z axis
tvelocityy += - (tvelocityy / abs (tvelocityy)) / 5
end if
if tvelocityx not= 0 then
main -> movecamera ("xy", tvelocityx) %moves camera in z axis
tvelocityx += - (tvelocityx / abs (tvelocityx)) / 5
end if
locate (1, 1)
%put "Object coords : ", spike (1) -> vector.x, " / ", spike (1) -> vector.y, " / ", spike (1) -> vector.z, " / "
% put "Object angles : ", spike -> obj.axy mod 360, " / ", spike -> obj.axz mod 360, " / ", spike -> obj.ayz mod 360, " / "
/*put "Camera coords : ", main -> camera.cx, " / ", main -> camera.cy, " / ", main -> camera.cz, " / "
put "Camera angles : ", main -> camera.axy mod 360, " / ", main -> camera.axz mod 360, " / ", main -> camera.ayz mod 360, " / "
put "Camera zoom : ", main -> camera.zoom, "X" %*/
% spike -> moveobject ("xz", 1) %rotates the object in xz axis
% spike -> moveobject ("yz", 1) %moves object in x axis
main -> drawobject (2, 2, 5) %draws the object with color 1 and 10 and in method 1
for i : 1 .. maxenemy
spike (i) -> drawobject (2, 14, 1) %draws the object with color 1 and 10 and in method 1
end for
View.Update
%delay (5)
cls
end loop
|
|
|
|
|
|
|
|