Posted: Sun Oct 29, 2006 4:41 pm Post subject: [Help] New drawings, images created are not appearing !!
Hey Im making a shooter game for comp engineering class and i need some help. Well heres the code so far.
code:
import GUI
setscreen ("graphics:1000;600")
var x, y, button : int
procedure draw (x, y : int)
View.Set ("offscreenonly")
%Scope casing
Draw.FillOval (x, y, 55, 55, black)
Draw.FillOval (x, y, 50, 50, white)
%Thick crosshair threads
Draw.ThickLine (x - 50, y, x - 35, y, 3, black)
Draw.ThickLine (x + 50, y, x + 35, y, 3, black)
Draw.ThickLine (x, y - 50, x, y - 35, 3, black)
Draw.ThickLine (x, y + 50, x, y + 35, 3, black)
%Thin threads
Draw.Line (x - 20, y, x + 20, y, red)
Draw.Line (x, y - 20, x, y + 20, red)
View.Update
end draw
loop
Mouse.Where (x, y, button)
draw (x, y)
cls
end loop
Well Now when I try to draw more objects, or images, which the scope shooter shoots they do not appear.
This is to be a game, where spaceships appear and the user has to shoot moving spaceships. So now I want to draw the spaceships and then get them moving around. All help is appreciated.
Btw, can you edit posts? Otherwise I would have added in other forum
Sponsor Sponsor
Ultrahex
Posted: Sun Oct 29, 2006 5:08 pm Post subject: (No subject)
no you cant edit posts in the help forums due to users after they having their problem completed they are removing their fixes to their problems along with changing their thread so searching for help in the forum was useless.
you could of actually just added to the bottom of your last thread i would have got around to it just now, but thats too late.
Im wondering if you are fluent in functions/procedures?, if so you could actually make a procedure to draw your crosshair to the graphic buffer then do the view update in the end of your main loop in order to clean up code.
The reason other things are probably not showing up is...
1. Your Doing the View.Update before all the drawing is done, and then clearing screen after drawing (as in you put new draw commands between your view update and cls)
... actually thats the only one i could think of
An Example Code where its not drawing everything would help BTW.
razrdude
Posted: Sun Oct 29, 2006 5:33 pm Post subject: (No subject)
hmm i tried what you said, and i got another line in there, now i guess I could try adding my spaceships and then get them moving. man why does turing have to be so hard. Anyone got any suggestions on where to go? Also as I have buttons to get to the game,
code:
var button1:int:=GUI.CreateButton(20,20,100,"START", game)
var button2:int:=GUI.CreateButton(200,20,100,"INSTRUCTIONS",instructions)
but when I put my drawing part in, I cannot have a procedure inside another procedure, so that part messed up.
hope u understand what i mean.
Ultrahex
Posted: Sun Oct 29, 2006 6:17 pm Post subject: (No subject)
you cant declare a procedure inside a procedure, but you can run a procedure inside a procedure.
for example:
code:
proc add (x,y:int)
put x+y
end add
proc squareadd (x,y:int)
add(x**2,y**2)
end squareadd
squareadd(5,10)
i think you may be confused in some of the fundamentals of programming
razrdude
Posted: Sun Oct 29, 2006 6:27 pm Post subject: (No subject)
I think I skipped on most of the fundamentals, when my teacher said , GUI or Game due on Monday. We just started Turing about early to mid last week and have this thing due on Monday.
I dont want anyones pity but help is appreciated.
I understand what you wrote there, but say I want my instructions to show, and then my program to run, how would I do that?
For example
code:
procedure Instructions
put "My instructions would go here"
put "further instructions"
end Instructions
after that i have the procedure for my drawings, but to get to that part I need to use buttons and buttons access a procedure...
Ultrahex
Posted: Sun Oct 29, 2006 6:48 pm Post subject: (No subject)
code:
proc runGame ()
%Put Game Loop Here
put "Game Running..."
end runGame
proc instruct ()
put "Instructions Here...."
%Probably want to put delay here
runGame ()
end instruct
instruct ()
thats basically how it is done, but the instruct procedure is ran by the button instead of by the command in your case,
which Monday BTW, as in tomorrow and when did he assign the assignment?
razrdude
Posted: Sun Oct 29, 2006 7:06 pm Post subject: (No subject)
yes Monday as In tomorrow, He assigned it last monday, but we had 6 mini question assignments due, so did those till like thurs, and started on friday. the teacher hasn't taught anything about turing. Also what you wrote, ill try that but im losing hope.
where is says
proc instructions
put "Instructions Here...."
%Probably want to put delay here
runGame ()
wat u mean by rungame? isint that the procedure of the game, what would go in the brackets.
If you have free time and would like to help me, can we talk on msn? Pm me and ill add you. Btw im in Canada, EST
razrdude
Posted: Sun Oct 29, 2006 7:31 pm Post subject: (No subject)
ok so i gave up on making a spaceship and now Just used a pic.
However, when I press Run, the pic shows in the right position and everything, but after a couple of seconds, it stops and gives me the error "Cannot Allocate Item. Out of id numbers (max 1000)." and it highlights the line with
spaceship := Pic.FileNew ("shipf.bmp")
any explanations?
Sponsor Sponsor
[Gandalf]
Posted: Sun Oct 29, 2006 8:37 pm Post subject: (No subject)
Is that code inside a loop? It shouldn't be. The error just means that you've declared the maximum amount of pictures that Turing can handle.
If the problem isn't that it's in a loop, post the rest of the code.
razrdude
Posted: Sun Oct 29, 2006 8:39 pm Post subject: (No subject)
this is the rest of the code, and no its not inside the loop, this is the only pic im using...
var x, y, button : int
procedure draw (x, y : int)
View.Set ("offscreenonly")
%Scope casing
Draw.FillOval (x, y, 55, 55, black)
Draw.FillOval (x, y, 50, 50, white)
%Thick crosshair threads
Draw.ThickLine (x - 50, y, x - 35, y, 3, black)
Draw.ThickLine (x + 50, y, x + 35, y, 3, black)
Draw.ThickLine (x, y - 50, x, y - 35, 3, black)
Draw.ThickLine (x, y + 50, x, y + 35, 3, black)
%Thin threads
Draw.Line (x - 20, y, x + 20, y, red)
Draw.Line (x, y - 20, x, y + 20, red)
var x, y, button : int
var spaceship : int
spaceship := Pic.FileNew ("shipf.bmp")
procedure draw (x, y : int)
View.Set ("offscreenonly")
%Scope casing
Draw.FillOval (x, y, 55, 55, black)
Draw.FillOval (x, y, 50, 50, white)
%Thick crosshair threads
Draw.ThickLine (x - 50, y, x - 35, y, 3, black)
Draw.ThickLine (x + 50, y, x + 35, y, 3, black)
Draw.ThickLine (x, y - 50, x, y - 35, 3, black)
Draw.ThickLine (x, y + 50, x, y + 35, 3, black)
%Thin threads
Draw.Line (x - 20, y, x + 20, y, red)
Draw.Line (x, y - 20, x, y + 20, red)
Pic.Draw (spaceship, 0, 0, picUnderMerge)
View.Update
end draw
loop
Mouse.Where (x, y, button)
draw (x, y)
cls
end loop
razrdude
Posted: Sun Oct 29, 2006 8:58 pm Post subject: (No subject)
dude i love you, thanks, if all of this works, imma donate all my bits to both of you. ok now i gotta make the spaceships move and have the the scope shoot them.
all nighter ..
Ultrahex
Posted: Sun Oct 29, 2006 9:25 pm Post subject: (No subject)
ya lol, it seems that way lol, that sucks for you man, teacher is BS, you should just contact me on IRC, if you do that stuff we have a channel and stuff. Probably could of helped you a lot faster.
razrdude
Posted: Sun Oct 29, 2006 9:29 pm Post subject: (No subject)
i used to mIRC for sum satellite stuff, but not anymore, hmm now im having issues with getting the spaceship to move and follow a path. yet again im stuck, and then after i get that working ill be stuck in making it recognize that the mouse click the ship.
help me pls? or lead me in the right direction.
Ultrahex
Posted: Sun Oct 29, 2006 9:54 pm Post subject: (No subject)
Ummm ya thats quite the problem you gut there, im not sure how i can help you. the mouse click on the ship should be that hard its just point inside a square collision.
what you gotta do is hand in something like this ...
code:
%Create Game Window
var gameWindowID : int
gameWindowID := Window.Open ("graphics:500;400")
View.Set ("offscreenonly")
% Frame Limiter
var startTime : int
var endTime : int
%Types
var scoreType := Font.New ("sans serif:10")
%Score System
var score : int := 0
class bullet
export struct, move, draw, x, y
var angle : int := 0
var x, y : int := 1
procedure struct (locX : int, locY : int, shipAngle : int)
x := locX
y := locY
angle := shipAngle
end struct
procedure move ()
x += round (cosd (angle) * 5)
y += round (sind (angle) * 5)
end move
procedure draw ()
drawfilloval (x, y, 2, 2, white)
end draw
end bullet
class bulletStack
import bullet
export addBullet, draw, move
var bullets : flexible array 1 .. 0 of ^bullet
var stackTop : int := 0
procedure addBullet (locX : int, locY : int, shipAngle : int)
stackTop += 1
new bullets, stackTop
new bullets (stackTop)
bullets (stackTop) -> struct (locX, locY, shipAngle)
end addBullet
procedure draw ()
for i : 1 .. stackTop
bullets (i) -> draw ()
end for
end draw
procedure move ()
for i : 1 .. stackTop
bullets (i) -> move ()
end for
end move
end bulletStack
class shipClass
import bulletStack
export struct, move, rotate, draw, go, shoot
var cX, cY : real %Center Point
var angle : int := 90
var moveAngle : int := 0
var magnitude : int := 0
var moveX : real := 0
var moveY : real := 0
%Array of 3 Points (Vertex's of Triangle)
var ptX : array 1 .. 3 of real
var ptY : array 1 .. 3 of real
ptX (1) := 0
ptY (1) := 10
ptX (2) := -6.0
ptY (2) := -5
ptX (3) := 6.0
ptY (3) := -5
var gun : ^bulletStack
new gun
procedure struct (x : int, y : int)
cX := x
cY := y
end struct
procedure move ()
%Add Velocity to Objects Position
cX += moveX
cY += moveY
%Checks To See If Moved Off Screen, If So Change It To Opposite Side
if (cX < -5) then
cX := 505
end if
if (cX > 510) then
cX := 0
end if
if (cY < -5) then
cY := 405
end if
if (cY > 410) then
cY := 0
end if
end move
procedure go (speedINC : int)
%Add Thrust Based on Angle of Ship
moveX += cosd (angle) * speedINC
moveY += sind (angle) * speedINC
%Speed Limiter - Needs Improvment
if (moveX > 5) then
moveX := 5
end if
if (moveX < -5) then
moveX := -5
end if
if (moveY > 5) then
moveY := 5
end if
if (moveY < -5) then
moveY := -5
end if
end go
procedure rotate (degrees : int)
for i : 1 .. 3
var tempx : real := ptX (i) * cosd (degrees) - ptY (i) * sind (degrees)
var tempy : real := ptX (i) * sind (degrees) + ptY (i) * cosd (degrees)
ptX (i) := tempx
ptY (i) := tempy
end for
angle += degrees
end rotate
var chars : array char of boolean
var ship : ^shipClass
new ship
ship -> struct (200, 200)
loop
cls
startTime := Time.Elapsed
drawfillbox (0, 0, maxx, maxy, black)
Input.KeyDown (chars)
if chars ('w') then
ship -> go (1)
end if
if chars ('s') then
ship -> go (-1)
end if
if chars ('d') then
ship -> rotate (-5)
end if
if chars ('a') then
ship -> rotate (5)
end if
if chars (' ') then
ship -> shoot ()
end if
ship -> draw ()
ship -> move ()