Posted: Fri Jan 18, 2013 11:06 pm Post subject: How Do You Make The Spaceship Shoot The Asteroid Need Help Due Monday Grade 11 Summutive
this is my grade 11 summitave for computer science and i do not really understand the class at all, we use the program turing. This is my game so far, how do i make the ship shoot a mistle at the asteroiods? help please!!
var font1 : int := Font.New ("serif:124")
var font2 : int := Font.New ("serif:20")
var font3 : int := Font.New ("Serif:20")
var font4 : int := Font.New ("Serif:20")
var mousex : int
var mousey : int
var button : int
var asteroid : int := Pic.FileNew("asteroid.jpg")
var asteroid3 : int := Pic.FileNew("asteroid3.jpg")
% This is the background
setscreen ("graphics")
colourback (black)
cls
color (17)
% This is what is on the main screen
procedure mainscreen
Font.Draw ("Asteriods", 10, 190, font1, white)
Font.Draw ("Play Game", 230, 100, font2, white)
Font.Draw ("Instructions", 230, 70, font4, white)
Font.Draw ("High Scores", 230, 40, font3, white)
end mainscreen
procedure playgame
var ship : int := Pic.FileNew ("ship.gif")
View.Set ("graphics:300;250),nobuttonbar")
var pic : array 0 .. 35 of int
const CTR : int := 48
pic (0) := ship
cls
for angle : 1 .. 35
pic (angle) := Pic.Rotate (pic (0), angle * 10, CTR, CTR)
end for
var angle : int :=0
var x : int := 300
var y : int := 300
var chars : array char of boolean
loop
Input.KeyDown (chars)
if chars (KEY_RIGHT_ARROW) then
if angle > 0 then
angle := angle - 1
else
angle := 35
end if
end if
if chars (KEY_LEFT_ARROW) then
if angle < 35 then
angle := angle + 1
else
angle := 0
end if
end if
if chars (KEY_UP_ARROW) then
x := x+round (2*sind(10*angle))
y := y+round (2*cosd(10*angle))
end if
if chars (KEY_DOWN_ARROW) then
if angle > 0 then
angle := angle - 1
else
angle := 35
end if
end if
Pic.Draw (pic (angle), x, y, picMerge)
Pic.Draw (asteroid, 30, 40, picMerge)
Pic.Draw (asteroid3,420, 90, picMerge)
Pic.Draw (asteroid,120, 336, picMerge)
delay (50)
cls
end loop
cls
Pic.Draw (ship, 270, 160, picMerge)
delay (1000)
end playgame
% This is the instructions to the game
procedure instructions
cls
colour (white)
put "Welcome to Asteroids.The object of this game is to destroy all of the asteriods."
put "while trying to avoid being hit.As you adavance to the next levels, the amount"
put "of points you get for each destroyed asteroid will increase."
put "Good luck,enjoy the game and have fun!"
put "Controls"
put "Up arrow makes you accelerate"
put "Down arrow makes you decelerate"
put "Left arrow makes you turn to the left"
put "Right arrow makes you turn to the right"
put "Space bar makes you shoot a bullet"
put "Press any key to continue.."
Input.Pause
cls
mainscreen
end instructions
mainscreen
% If play game is selected
loop
Mouse.Where (mousex, mousey, button)
if mousex > 230 and mousex < 350 and mousey > 100 and mousey < 125 and button = 1 then
playgame
elsif
mousex > 230 and mousex < 350 and mousey > 70 and mousey < 95 and button = 1 then
instructions
end if
end loop
Sponsor Sponsor
Raknarg
Posted: Sat Jan 19, 2013 12:09 am Post subject: RE:How Do You Make The Spaceship Shoot The Asteroid Need Help Due Monday Grade 11 Summutive
If you really just don't understand what you're doing, the best thing to do is to switch to an easier project. I don't mind teaching concepts, but not just to help someone slap together a last minute game.
ashlyn10
Posted: Sat Jan 19, 2013 2:23 pm Post subject: RE:How Do You Make The Spaceship Shoot The Asteroid Need Help Due Monday Grade 11 Summutive
we cant switch games the teacher assigned us a game and he said all i need to do now is get the ship to shoot bullets.
Tony
Posted: Sat Jan 19, 2013 4:47 pm Post subject: RE:How Do You Make The Spaceship Shoot The Asteroid Need Help Due Monday Grade 11 Summutive
Alright. So you've skipped the standard questions of:
What problem are you having?
What have you already tried doing to solve that problem?
Posted: Sun Jan 20, 2013 11:01 am Post subject: Re: How Do You Make The Spaceship Shoot The Asteroid Need Help Due Monday Grade 11 Summutive
For the bullet shooting, you can set a process.
Such as
Turing:
process bulletshooting (x, y :int) % Collision detection here if distance_of_whatever <= radius1 + radius2 then % Whatever after the collision occurs. elsif % Whatever if it doesn't. end bulletshoot
So you just basically have to find a collision detection process and also by using Input.Keydown you can make bullets shoot. So when 'g' is pressed, import a picture whatever and make it move one pixel towards the direction it was shot etc. Bascially for the collision you can use the radius between the two pictures and when sum of those are smaller than the distance between, the asteroids explode whatever. Just have to think and try a lot of things.
Insectoid
Posted: Sun Jan 20, 2013 12:02 pm Post subject: RE:How Do You Make The Spaceship Shoot The Asteroid Need Help Due Monday Grade 11 Summutive
Quote:
For the bullet shooting, you can set a process
This is actually a very bad thing to do, and will cause all sorts of problems very quickly.
SAValkyrie
Posted: Sun Jan 20, 2013 12:09 pm Post subject: Re: How Do You Make The Spaceship Shoot The Asteroid Need Help Due Monday Grade 11 Summutive
That is true, there is a very interesting post by Cervantes by not using processes lol... I am used to using processes so that was the first thing that came to my mind. He could use procedures then maybe..
Raknarg
Posted: Sun Jan 20, 2013 10:14 pm Post subject: RE:How Do You Make The Spaceship Shoot The Asteroid Need Help Due Monday Grade 11 Summutive
The funny thing about that is that people use processes like procedures anyways, so it doesn't really make a difference to you programming wise
Sponsor Sponsor
Insectoid
Posted: Sun Jan 20, 2013 10:17 pm Post subject: Re: RE:How Do You Make The Spaceship Shoot The Asteroid Need Help Due Monday Grade 11 Summutive
Raknarg @ Sun Jan 20, 2013 10:14 pm wrote:
The funny thing about that is that people use processes like procedures anyways, so it doesn't really make a difference to you programming wise
It actually does make a difference. A pretty significant difference. Your code will often execute out of order, which can cause all sorts of problems, and it will be next to impossible to debug.
Tony
Posted: Mon Jan 21, 2013 1:28 am Post subject: RE:How Do You Make The Spaceship Shoot The Asteroid Need Help Due Monday Grade 11 Summutive
It... depends. The problem is that people using Turing's processes don't understand Turing's processes and that leads to as much problem as any other scenario where you throw code at the screen until something sticks.
The most common method of debugging of "follow your code line by line" goes out the window, as the order is no longer guaranteed.
Worse yet, processes are almost always discovered/taught no further than "this is a magic box that will unblock a loop". No synchronization. No locks.
Posted: Mon Jan 21, 2013 5:03 pm Post subject: RE:How Do You Make The Spaceship Shoot The Asteroid Need Help Due Monday Grade 11 Summutive
No, that's what I meant. I was saying that switching to procedures won't really change anything, because syntax-wise people use them the same. It's not really like learning anything new for them.
Insectoid
Posted: Mon Jan 21, 2013 5:46 pm Post subject: RE:How Do You Make The Spaceship Shoot The Asteroid Need Help Due Monday Grade 11 Summutive
Quote:
It's not really like learning anything new for them.
You'd be surprised at just how much trouble people have moving from individual animations with their own loops inside processes, to proper frame-by-frame animations with procedures inside a single main loop.
SAValkyrie
Posted: Mon Jan 21, 2013 7:04 pm Post subject: Re: How Do You Make The Spaceship Shoot The Asteroid Need Help Due Monday Grade 11 Summutive
Just out of curiosity, what kinds of problems will use of processes create? In my case, I've never had one so.. just wondering what they could be
Insectoid
Posted: Mon Jan 21, 2013 8:04 pm Post subject: RE:How Do You Make The Spaceship Shoot The Asteroid Need Help Due Monday Grade 11 Summutive
Turing:
process makePositive(i :int) if i < 0then
i *= -1 endif end makePositive
var x :int
loop
x := -1 fork makePositive (x) putsqrt(x) endloop
Intuitively, this code should output 1 forever. However, it's possible (and inevitable) that Turing will try to run sqrt(x) before makePositive finishes making it positive. x will thus be negative, and the program will crash.
If you're processing data in sequential stages, you might end up with entirely the wrong answer at the end because the stages executed out of order. Say you want to square a number, then multiply it by 3, then add 2, then divide it by 5. If all of those stages live in their own process, you'll get all sorts of answers for the same input because the order gets scrambled.
SAValkyrie
Posted: Mon Jan 21, 2013 10:03 pm Post subject: Re: How Do You Make The Spaceship Shoot The Asteroid Need Help Due Monday Grade 11 Summutive
Oh so when you have multiple processes, how they process something is random, not sequential? If that is the case, that will be a big problem when one's using multiple processes..