Computer Science Canada Assistance with some Game Elements |
Author: | Beastinonyou [ Thu Oct 06, 2011 3:08 pm ] |
Post subject: | Assistance with some Game Elements |
So, I'm getting a good head-start on my Final Project already, and am going to start coding the individual elements, then put it all together later on. For any concepts or elements that I don't necessarily know how to do from scratch, I will ask here, and hope you can give me a tip or direction to go to accomplish that. Some pseudocode would be helpful for some, but for others, I would just need a good shove in the right direction. As for the moment, how would I go about doing these things: 1. Putting a delay on doing something, like if you had a gun, you are only able to shoot once every X seconds/milliseconds, without interrupting the rest of the program (Time.Delay would delay whole program wouldn't it?) 2. Waves of enemies (regarding number of enemies) / Levels 3. If you were to draw an object at a certain angle depending on the mouse coordinates (character holding a gun, aiming where mouse is), how would you apply a restriction to where it aims (like, the gun only aims where your mouse is, if the angle at which that gun is pointing is within an X degree angle) 4. In a mouse-oriented game, are you able to have an image be the mouse cursor when in the game? I know you can just draw the picture to where the mouse coordinates are, but is there a way to make the regular image cursor be replace by the image If I get any more questions, I'll add them later. Until then, I'll be working on the structure and other elements of the game. This is so, by the time I'm at the point in trying to figure these things out, I've already received feedback on how I can successfully integrate it. Plus, maybe if It's good enough, I'll submit it, and if people like it enough, I'll most likely port it to a mobile (more like, overhaul it and make it a lot better, more features, etc.) Thanks in Advance... |
Author: | DemonWasp [ Thu Oct 06, 2011 4:44 pm ] |
Post subject: | RE:Assistance with some Game Elements |
1. Yes, Time.Delay will stop your whole program. You have to do this by keeping track of when you last did that thing; by comparing that to the current time, you can figure out whether you're allowed to do that again right now. 2. There are a lot of different ways to handle this. Think about exactly how / when you want your enemies to show up, and base your solution on that. 3. What you want to do is restrict variable "angle" to a range ( -45, +90 ), for example. You can do this by saying "if angle is above 90, use 90; if angle is below -45, use -45; otherwise, use angle." This should be pretty straightforward. 4. I'm pretty sure Turing doesn't support that. Plenty of other languages do, but not Turing (as far as I know). |
Author: | Dreadnought [ Thu Oct 06, 2011 7:54 pm ] | ||
Post subject: | Re: Assistance with some Game Elements | ||
1- There are two ways I like to do this. The first is using Time.Elapsed, like DemonWasp said, to find out at what time the gun fires then use a loop in your program to check when a certain time has passed. The second way (which I prefer) is using a separate process which runs alongside your main process. Something like:
This way this separate process is halted by Time.Delay instead of your main process. You call this process using fork 'process_name'. Then you just tell the game not to fire when your variable (ex gun_can_fire) is false. 2- If you just want to store something like numbers of mobs/types of mobs I suggest using records and/or arrays to store this information. But as DemonWasp said there are many ways to this and you should choose what works best for you. 3- Well, assuming that your gun is in the center of your screen, your probably finding this angle using the distance from the mouse cursor to the center of the screen. I would just put a cap on this distance. Say if the distance is larger than some maximum amount then set the distance equal to that amount. 4- No that's not possible in turing. If you are ready to kill to do this then you could perhaps write a short program in a different language to change the cursor, save it as an executable file, then run it with turing using Sys.Exec but I can't promise that this will work and it seems like too much effort anyway. And if you haven't already, I highly recommend browsing The Turing Walkthrough http://compsci.ca/v3/viewtopic.php?t=8808, its amazing. Good luck with your game. |
Author: | Raknarg [ Mon Oct 10, 2011 10:04 am ] | ||
Post subject: | RE:Assistance with some Game Elements | ||
I acheived this using a counter. Its rather simple, even if you have multiple gun types.
This code will ensure that the guy will only shoot once the loop has run at least 50 times. |
Author: | Raknarg [ Mon Oct 10, 2011 10:06 am ] | ||
Post subject: | RE:Assistance with some Game Elements | ||
As for your third question, I have a program I made you can look at that deals with this:
|
Author: | Beastinonyou [ Mon Oct 10, 2011 12:08 pm ] | ||
Post subject: | Re: RE:Assistance with some Game Elements | ||
Raknarg @ Mon Oct 10, 2011 10:04 am wrote: I acheived this using a counter. Its rather simple, even if you have multiple gun types.
This code will ensure that the guy will only shoot once the loop has run at least 50 times. That's another good way to do it, but I find Dreadnought's approach to delaying it works great, and very easy. just pass parameters for the delay on the gun, and fork it. As for your detailed approach for my third question, I Greatly Appreciate the time and effort you put into that example. However, I think I'm going to be using pictures guns, and rotating them respectively. Although, you need a rotated picture for every angle within your range. Right now, I'm trying to get the pictures of the guns to rotate on the end of the barrel of the gun, rather than the bottom left corner of every picture, without getting a part of the gun chopped off when rotating. Also, I drew up a zombie last night on Photoshop, and then used Puppet Warp to make 4 Frames, and made it into a gif. How would I go about making the Zombie move, but cycling through the images. What I'm thinking is having a counter in the loop, and having it increment (1 to 4), drawing the frames by that counter, and when it gets to 4, reset it back to 1. Btw, Thanks for all feedback from anyone. I'm sure my final result will be great, considering It won't be due til' the end of January. |
Author: | Insectoid [ Mon Oct 10, 2011 1:17 pm ] |
Post subject: | RE:Assistance with some Game Elements |
I dunno how to stop bits of your gun getting clipped in rotation (might even just be your draw order) but limiting it is pretty easy. You'll probably want to pre-generate rotated images for every other degree of rotation to conserve image space (Turing can only load 1000 pictures I think) without sacrificing execution speed. If the mouse is at a higher angle than the gun is allowed to be, just point the gun at the max angle. Same for minimum angle. Finally, for your zombie, that's exactly what you should do. I've never used a gif in Turing, but there should be documentation about it. |
Author: | Raknarg [ Mon Oct 10, 2011 4:29 pm ] |
Post subject: | RE:Assistance with some Game Elements |
Pic.FileNewFrames I dont quite know how it works, but it seems to be made for the use of gifs. i have another method if you like, if you can split the gif into seperate images. |
Author: | Beastinonyou [ Mon Oct 10, 2011 7:11 pm ] | ||
Post subject: | Re: Assistance with some Game Elements | ||
There I have just a simple way of loading 4 Frames of the Zombie, drawing them, and moving them across the x-axis. Now for other frames for different sprites, it's just a matter of adding them into the initializing for structure, and storing in an array Side Note: Where did you find "Pic.FileNewFrames"? I looked and doesn't exist in Turing Documentation, nor recognized by syntax |
Author: | Raknarg [ Mon Oct 10, 2011 7:55 pm ] |
Post subject: | RE:Assistance with some Game Elements |
Strange. Idk, i was looking through the syntax database here on Compsci. So about your second question: What exactly are you trying to do? |
Author: | Beastinonyou [ Mon Oct 10, 2011 8:55 pm ] |
Post subject: | Re: Assistance with some Game Elements |
Well, I'm basically doing a game very similar to this, in regards to some gameplay elements: http://www.2flashgames.com/f/f-Stickman-Madness-3-Stronghold-7244.htm Once I can get the basics of the game down, I have some ideas of how I can add another game mode or two, to make it even better. Obviously though, this isn't going to be a stick-men game. How would I go about creating waves of enemies, such as how many of each type, when they appear, how close together they are (mobs / cluster), etc. Should I make enemies increment by a constant, use random variable to determine type, and random variable to choose when to spawn enemies? What about boss / harder levels? Also, I could instead use a percentage based system, where a certain type of enemy will have a 10% chance of spawning, compared to the more common 50%, etc. Then, I could just keep track of how many total have been spawned, and correlate that to how many per level / wave. Seems like I think about stuff more when I'm trying to explain how I should do something, but a second opinion is always helpful. I think I'm going to pause on the animation and sprites for the moment, and get the game to function, rather than focusing on Aesthetics. |
Author: | Raknarg [ Tue Oct 11, 2011 2:54 pm ] |
Post subject: | RE:Assistance with some Game Elements |
I think I would go with a percentage. The only other way I could think about having a specific order of enemies would be using a text file with a set of commands. |
Author: | Dreadnought [ Tue Oct 11, 2011 9:12 pm ] |
Post subject: | Re: Assistance with some Game Elements |
Well, first off, the rotating gun (sorry that I didn't visualize it properly last time). To change the point at which the picture rotates, changing x and y in Pic.Rotate (picID, angle, x, y) should do the trick. It might take a bit of experimenting to get the right place. The cutting off of corners is a problem since the resulting picture is the same size as the original. So you could make the picture bigger by adding a margin of background color around the gun in photoshop. Or you could rotate the gun in photoshop and save all angles you want (this is kinda a last resort). For animating sprites, Raknarg is right Pic.FilenewFrames and other built-in functions exist to help do the kind of things your thinking of. If you don't have that function then you probably have an old version of turing on your computer. I think anything past 4.0.0 should have these. (the final version is 4.1.1a but you should actually use 4.1 because they screwed the last version up). The download link is in a post at the top of the forum I think. If you do have a relatively up-to-date version you should also look at the built-in Sprite procedures that are great for animating images. Its much easier to work with than the Pic functions in my opinion. You will need a loop like you described anyway to keep track of gif frames but the Sprite stuff helps if you want to have many animated images on a background. Finally, the mob waves. This is really up to you. You could store the number of each kind of enemy for each level in an array that you either hardcode into your program or you could store it in a text file. You could also just have an array to store chances of spawning and or level at which certain enemies start to spawn. There really is no best way to do this. Some ways offer more control over spawning, others are simpler and can be scaled or changed much easier. I'd suggest not storing huge lists of numbers to control mob waves. My favorite is something along the lines of a minimum level for each mob to start appearing and then either a multiplier, an adder or a percentage (like you suggested) to allow more spawning in later waves. |
Author: | Beastinonyou [ Tue Oct 11, 2011 10:04 pm ] | ||
Post subject: | Re: Assistance with some Game Elements | ||
I have experimented with rotating guns already, and have got a couple to work very well, after fiddling around with the point in which it rotates, and extra space around the image. Also, I came across that today during class, as I saw someone in the documentation on Sprite.Animate and saw that line: "Pic.FileNewFrames", and I'm like, Holy Crap. I looked through mine, and didn't see it. I'm assuming that is because I have installed turing onto the computer (most recent version that lets you install without having to go to File > Open everytime to open a Turing File), so by actually running the 4.1.1a or whatever (infinite .1's.. lol), I'll most likely see this Now, what I'm working on, is if I have 5 y-values (for enemies to move along, like rows), and I randomly generate a variable 1 to 5, and depending on that variable, an enemy will spawn in that row, and continue to move along that axis.
that manages to show an example of the rows, however, I am repeatedly changing rows by calling the chooseRows function over again. How would I generate a random row an enemy is supposed to spawn to, and keep it moving along that same row, doing this everytime an enemy spawns. |
Author: | Dreadnought [ Wed Oct 12, 2011 5:16 pm ] |
Post subject: | Re: Assistance with some Game Elements |
Ok, I haven't done much in Turing in a while so I went crazy. What you want is a way of storing data about multiple enemies. You could use an array of records, but that means you have to set the size of the array to the maximum number of enemies you can ever have. You could use a flexible array and then you could resize it when you want to make it bigger, but my understanding of flexible arrays are that they are not completely properly implemented in Turing and I have had issues working with them in the past. So my solution to this is a linked list (a collection in Turing). If you don't know what that is, think of it as a chain. Each link in the chain tells you what the next and previous links are and also contains its own data. They use pointers which essentially reference the memory location where your data is stored. So each element of the list has a pointer that points to the next and previous elements. This is nice because we can easily add or remove elements by changing pointers. I'm not sure how advanced you are in Turing but here is a bunch of example code that does what your example did while keeping enemies on their row. Note that I'm using the Sprite module and many short forms that I have indicated. I had to attach it instead of posting it because its nearly 200 lines (ya I love linked lists that much). Please remember that is only my suggestion (a long one too) and that there are other ways of accomplishing what you want with or without a linked list. If you do like this approach though but want to go much deeper into personalizing enemies then you could take a look at classes. But that might be too much for what you're trying to do. Hope this helps. |
Author: | DemonWasp [ Wed Oct 12, 2011 6:22 pm ] |
Post subject: | RE:Assistance with some Game Elements |
@Dreadnought: Pst... compsci.ca/v3/viewtopic.php?t=20302 . Good job, though. |
Author: | Raknarg [ Wed Oct 12, 2011 6:41 pm ] | ||
Post subject: | RE:Assistance with some Game Elements | ||
Actually, a flexible array and a record would be very effective tools:
I'm pretty sure this will work just as well, but has less code |
Author: | Dreadnought [ Thu Oct 13, 2011 1:03 pm ] |
Post subject: | Re: Assistance with some Game Elements |
@Demonwasp Oooooh, I don't know Java (sad, I know), but I looked at your post and code quickly and it looks really, really cool. Maybe I'll play around with it if I have enough spare time. Probably could learn quite a bit from carefully reading it carefully. I hope it didn't seem like I was trying to duplicate someone else's work with my code (although I'm far from the beast of a project you posted). I just wanted to make a quick example for Beastinonyou. @Raknarg Yes, I agree flexible arrays may be slightly easier to work with than a linked list and would be very effective. In fact, in the past, I have used flexible arrays to do almost exactly what I did with the list. But, I also ran into weird problems and compile-time errors when trying to manipulate the arrays in some complicated ways, though I did find ways to do what I wanted in the end. Also, I have no idea how efficient Turing is at resizing arrays (especially large ones). I guess what I mean by all this, is that either method (flexible array or linked list) will work, but I like to feel that I know what's going on in my program and I find linked lists are more straight forward for my understanding. |
Author: | DemonWasp [ Thu Oct 13, 2011 6:57 pm ] |
Post subject: | RE:Assistance with some Game Elements |
@Dreadnought: I copied most of that from everybody's CS101 course, so don't feel like you're "duplicating" anything...everyone duplicates it. |
Author: | Raknarg [ Thu Oct 13, 2011 7:24 pm ] |
Post subject: | RE:Assistance with some Game Elements |
@Dreadnought Turing was never particularily effecient in the first place. However, in comparison with other methods in turing, I find that resizing array does not seem to drag too much on speed. There are other things like pictures and massive amounts of calculations that seem to drag much more than that. |
Author: | Beastinonyou [ Sat Oct 15, 2011 6:07 pm ] |
Post subject: | Re: Assistance with some Game Elements |
Ok, I've done some reading through Cervantes 3 Part tutorial on Classes. Obviously, other languages are "OO", so would doing my assignment using Classes, etc (OOT) be good practice and better understanding when I learn a new language later on (after end of semester). Before I even started Turing, I tried a shot at C++ and Java, and I had no idea what the hell all it was for.. I was just memorizing stuff. But now at least I know what's going on. At least after looking at how classes work in Turing, it makes me wonder.. Would it be better to program my game using Classes and such, and would it be easier / harder? More Code / More Efficient? I don't know if the teacher plans on covering classes and such in class, and I've always gone above and beyond the regular lessons. TL;DR: Should I attempt my project using classes and such (OOT), or should I just stick to the procedural stuff.. On a side note, here's the course I'll be applying to in February: http://www.fanshawec.ca/programs-courses/full-time-programs/cpa2 |
Author: | Aange10 [ Sat Oct 15, 2011 6:50 pm ] |
Post subject: | RE:Assistance with some Game Elements |
Beastinonyou wrote: Obviously, other languages are "OO", so would doing my assignment using Classes, etc (OOT) be good practice and better understanding when I learn a new language later on (after end of semester). OO is a paradigm. Not all languages are OO, infact more aren't then are; as holds true to any other paradigms (Like Object Oriented, Scripted etc.). Beastinonyou wrote: At least after looking at how classes work in Turing, it makes me wonder.. Would it be better to program my game using Classes and such, and would it be easier / harder? More Code / More Efficient? don't know if the teacher plans on covering classes and such in class, and I've always gone above and beyond the regular lessons. Going above and beyond is definitely worth it! Ask your teacher if you are covering it, i have not gotten the privileged of having a formal instructor, so i'm not sure. Easier/Harder really depends. If it's an RPG you will definetly want a polymorphism system. The bigger the game, the more valuable classes would [probably] become. However it's not mandatory that you use classes. I've seen some pretty good games, and high marks from people who never touched classes. It's really up to you. I don't know much about them, other than what the tutorial covered. As far as efficiency is concerned, I'm not sure. If by Efficient you mean less time wasted and less code coded, then it would depend on what your doing. |
Author: | Raknarg [ Sat Oct 15, 2011 8:36 pm ] |
Post subject: | RE:Assistance with some Game Elements |
Classes don't make anything faster. If anything, it takes longer to import/export stuff. However, you have to consider the fact that right now you are writing programs that will be max like 3000 lines or something. All classes are for are to organize procedures and stuff to make the actual game itself easier to code. I think that for this program, you could try classes if you like, but you probably don't actually need them. As for your class, my teacher didn't go into them. However, it was a grade 11 class full of newbies. You could try them. In fact, you could even consider a game where it would be useful, like a tower defense. |
Author: | Beastinonyou [ Sat Oct 15, 2011 9:46 pm ] |
Post subject: | Re: Assistance with some Game Elements |
Alright, I can see how classes wouldn't really be Suitable for something simple and non-complex as my project. My class is an 11/12 split actually, and obviously, at the end of this semester, I should start spending my spare time (on my Spare in middle of the day) programming in a different language. Now, In the college course I'll be applying to, both Java and C++ looks to be primary language focus. A question that I'm sure has been asked a gazillion times before, which should I invest more time into? / Start to learn First? I tried to learn both back in gr.10, but I had about much success as my grandmother would trying to learn how to use e-mail. I have also spent a good 2 weeks in C back in August. I feel like I'm leaning more towards C++ as for the moment. |
Author: | Raknarg [ Sat Oct 15, 2011 10:24 pm ] |
Post subject: | RE:Assistance with some Game Elements |
One thing that many people dont realize, is that learning new syntax is easy, but learning ideas on a complex language is harder. I would stick to turing just so you can learn other concepts and such. Remember that people have gone to Waterloo with only knowledge of turing or less. However, I've heard people recommending python or ruby as the next language to learn |
Author: | Dreadnought [ Mon Oct 17, 2011 4:10 pm ] |
Post subject: | Re: Assistance with some Game Elements |
I completely agree with Raknarg, you shouldn't worry too much about getting ahead for college CS classes by learning a language. Raknarg wrote: Remember that people have gone to Waterloo with only knowledge of turing or less. This is true. In fact Waterloo does not even ask that students entering CS have taken the course in high school. So I wouldn't worry too much about your college program. That being said its not a bad to learn another language and which one may not be important. I have heard that python is much easier to learn than C++ or Java. And about the classes, everything has pretty much been said. Their real benefit is making large programs better structured and easier to work with. I doubt your teacher will introduce them in class. They are probably overkill for what your doing. (But sometimes its fun to use a chainsaw to cut a stick ![]() |
Author: | Beastinonyou [ Mon Oct 17, 2011 6:54 pm ] |
Post subject: | Re: Assistance with some Game Elements |
Dreadnought wrote: And about the classes, everything has pretty much been said. Their real benefit is making large programs better structured and easier to work with. I doubt your teacher will introduce them in class. They are probably overkill for what your doing. (But sometimes its fun to use a chainsaw to cut a stick ![]() Yea, nice analogy btw ... I also doubt we will cover or touch anything related to classes, and for the teacher has still got quite a few concepts to cover. Tomorrow we're doing String Manipulation. He says that surely, I'll be well-prepared for College, because a Computer Science credit in high school isn't a requirement. They assume no knowledge of programming experience. |
Author: | Raknarg [ Wed Oct 19, 2011 3:41 pm ] |
Post subject: | RE:Assistance with some Game Elements |
Well if you are going to get used to making games, classes will be an asset. If you really want to learn how to use them, go ahead and practice them |