I wanted to make a game. And I wanted it to be original. So by just thinking about some of my previous games and other random stuff that drifted through my mind I came up with this idea somehow.
The basic idea is pretty simple. Every screen is a closed room and is divided into X squares (views). All are visible at once and are fixed. Now, the character can jump and stuff and interact with creatures and objects. But for all the squares excpet the one the character is in, time is frozen. Which means that all the objects and creatures there just freeze, then being restored and resuming all actions when they are unfrozen. Or, time is frozen only in the current square. Or, time freezes/unfreezes in all squares the character enters. Or... yeah, you get the idea. Anyway, this would make some very interest puzzling possibilities. I think. Because I haven't come up with any yet. Because I have been busy trying to get the basics to work.
(http://i48.tinypic.com/wbf8rq.jpg)
Everything seems to work except that the creatures are frozen or unfrozen all the time, not caring about views. I know where the fault is, but can not really figure out why or how I can fix it.
Did I mention I use Game Maker? Well it's pretty simple, so you should have no problem understanding if you have basic programming knowledge. The following results in the monster being permanently frozen:
Information about object: char
Sprite: CHAR
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent: <no parent>
Mask: <same as sprite>
Create Event:
set variable view to 4 //starting view
Step Event:
set variable view to 28 //after subtracting all views it is outside of it will have the value of the current view number
Keyboard Event for <Left> Key:
jump relative to position (-5,0)
Keyboard Event for <Up> Key:
jump relative to position (0,-5)
Keyboard Event for <Right> Key:
jump relative to position (5,0)
Keyboard Event for <Down> Key:
jump relative to position (0,5)
Mouse Event for Glob Left Pressed:
restart the game
Other Event: Outside View 0:
set variable view relative to -0 //just for the sake of it
Other Event: Outside View 1:
set variable view relative to -1
Other Event: Outside View 2:
set variable view relative to -2
Other Event: Outside View 3:
set variable view relative to -3
Other Event: Outside View 4:
set variable view relative to -4
Other Event: Outside View 5:
set variable view relative to -5
Other Event: Outside View 6:
set variable view relative to -6
Other Event: Outside View 7:
set variable view relative to -7
Information about object: mon
Sprite: MON
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent: <no parent>
Mask: <same as sprite>
Create Event:
set variable view to 4 //starting view, although it will not change view
set variable freeze to 0
set variable unfreeze to 0
set variable frozen to 0
set the gravity to 0.1 in direction 270 //gm is weird, 270 is down
set the vertical speed to -5 //will jump
Step Event:
if freeze is equal to 1 //if it is about to gain frozen status
set variable frozen to 1 //make it frozen
set variable freeze to 0
if unfreeze is equal to 1 //if about to remove frozen status
set variable frozen to 0 //make it unfrozen
set variable unfreeze to 0
if view is not equal to char.view //if they are in different squares (if this is inverted it will remain unfrozen instead)
if frozen is equal to 0 //(if this is inverted it will remain unfrozen instead)
set variable freeze to 1 //it will become frozen next step
else
set variable freeze to 0
else
if frozen is equal to 1
set variable unfreeze to 1 //will become unfrozen next step
if freeze is equal to 1
set variable _vspeed to vspeed //storing the variable
set variable vspeed to 0
set the gravity to 0 in direction 270
if unfreeze is equal to 1
set variable vspeed to _vspeed //loading the variable
set the gravity to 0.1 in direction 270
if frozen is equal to 1
exit this event
set variable view to 28 //after subtracting all views it is outside of it will have the value of the current view number
Collision Event with object wall:
if frozen is equal to 1
exit this event
set the vertical speed to -5 //this will make it constantly jump if unfrozen
Other Event: Outside View 0:
if frozen is equal to 1
exit this event
set variable view relative to -0 //just for the sake of it
Other Event: Outside View 1:
if frozen is equal to 1
exit this event
set variable view relative to -1
Other Event: Outside View 2:
if frozen is equal to 1
exit this event
set variable view relative to -2
Other Event: Outside View 3:
if frozen is equal to 1
exit this event
set variable view relative to -3
Other Event: Outside View 4:
if frozen is equal to 1
exit this event
set variable view relative to -4
Other Event: Outside View 5:
if frozen is equal to 1
exit this event
set variable view relative to -5
Other Event: Outside View 6:
if frozen is equal to 1
exit this event
set variable view relative to -6
Other Event: Outside View 7:
if frozen is equal to 1
exit this event
set variable view relative to -7
So, can anyone tell me what I missed/did wrong? It seems it's something with the if view is not equal to char.view and the following if frozen is equal to 0, or the whole block.
Oh and ofcourse the source file so you can play around with it!
http://www.mediafire.com/?wzudyryntgk
Many thanks, any answer will be appreciated.
For something like this, you should probably be using GML.
I think to freeze/unfreeze you should be using the functions:
Deactivating instances
Please be aware that deactivating and activating instances can sometimes lead to unexpected problems. So you are strongly advised not to use this feature except for very simple situation like the ones described below. The feature is mainly left in for backward compatibility.
When you create large room, for example in platform games, with a small view, many instances lie outside the view. Such instances though are still active and will execute their events. Also when performing collision checks these instances are taken into account. This can cost a lot of time, which is often not necessary. (For example, often it is not important whether instances outside the view move.) To solve this problem Game Maker contains some functions to deactivate and activate instances. Before using them you must though clearly understand how they work.
When you deactivate instances they are in some sense removed from the game. They are not visible anymore nor are any events executed for them. So for all actions and functions they don't exist anymore. This saves a lot of time but you have to be careful. For example, when you delete all instances of a particular type, deactivated instances are not deleted (because they don't exist). So don't think that a key a player picks up can unlock a deactivated door. Also persistent deactivated instances are not moved over to the next room (even though they are persistent). Also make sure that after you deactivate an instance that you no longer execute code for it. This can in particular happen when an instance deactivates itself. In general you better never have an instance deactivate itself.
The most crucial mistake you can make is to deactivate the instance that is responsible for the activation. To avoid this some of the routines below allow you to insist that the calling instance should not be deactivated itself.
Here are the available routines:
instance_deactivate_all(notme) Deactivates all instances in the room. If notme is true the calling instance is not deactivated (which is normally what you want).
instance_deactivate_object(obj) Deactivates all instances in the room of the given object. You can also use all to indicate that all instances must be deactivated or the id of an instance to deactivate an individual instance.
instance_deactivate_region(left,top,width,height,inside,notme) Deactivates all instances in the indicated region (that is, those whose bounding box lies partially inside the region). If inside is false the instances completely outside the region are deactivated. If notme is true the calling instance is not deactivated (which is normally what you want).
instance_activate_all() Activates all instances in the room.
instance_activate_object(obj) Activates all instances in the room of the given object. You can also use all to indicate that all instances must be activated or the id of an instance to activate an individual instance.
instance_activate_region(left,top,width,height,inside) Activates all instances in the indicated region. If inside is false the instances completely outside the region are activated.
For example, to deactivate all instances outside the view and activate the ones inside the view, you could place the following code in the step event of the moving character:
{
instance_activate_all();
instance_deactivate_region(view_xview[0],view_yview[0],
view_wview[0],view_hview[0],false,true);
}
In practice you might want to use a region slightly larger than the view.
Ok, it's all working C)
YAY!
I've attached a .gmk for you (zipped).
open it up and have a look and fiddle with it to get the feeling of how it works. i suggest you look up parent objects i the help manual, it really helps. (i know, wtf? a helpful help file! XD)
Edit: I've downloaded your source and had a fiddle, and am still working on it. i will upload it soon
Ok, i have now finished fiddling with your version, and it's all working. Instead of using views to do all the work (which i think is a little messy :^^:), it now relies on the squares. for the final game, you should either make these invisible, or give them a thin black border. i've attached it as well. working.zip was my test file, times square.zip is my modified version of your source (the new one)
about parent objects -
You have to be careful with parent objects, if you call their events, it basically gets the code out of the parent and chucks it into the child object. therefore, if you exit from within a parent object, it will exit in the child object.
I'll d/l your source and see whats going wrong :)
Edit: WHOA... whats with all the mario bs? it's i right mess, i'll see if i can figure something out :)
Edit: 2Do you actually want all the mario stuff, or are you just using it for the engine?
I've had a fiddle around, and i think the best path with this thing is to figure out how the platform engine works, and then to write your own engine from scratch. It's not too hard, if you want i can help you out. (I'm about to start anyway C)p) This is simply because the pre-written engine has way to much functionality than you need (as far as i can tell).
Edit: haven't been able to do much, really, as i have to study and whatnot for exams next week. I'll have another look at in a week or so
Hey ho, this is not dead! Stuff just got in between and then I sorta forgot it.
But I have been working on it a little, trying to implement those physics. It didn't go very well, so the other day I just removed everything and started from scratch. I encountered something that may be easy to go around, but it really annoys me and has left me clueless. I just tried to make the monster stop (freeze) when it hit the characters head, and then proceed falling when the character stepped away. The result is the monster bouncing up and down a few pixels on the characters head. This is really strange, because absolutely nothing in either the step or collision event says that it should ever move upwards. The only things that can give it a negative vspeed is either loading a negative _vspeed (stored vspeed, used when freezing and unfreezing) or colliding with the ground. It certainly does not collide with the ground, so it must be the _vspeed? Well yes, silly me, it is. The _vspeed is set to -1 as default, and explains it all. When I set it to 0 or lower the monster goes through the character instead, though. Did I also mention the game goes in laggy slow mo now?
Well that's a new problem then! Wouldn't mind if someone helped me with the actual stop thing though. If you are lazy here is the code, or you can download below for tweaking and testing.
if (freeze=1) {frozen=1;freeze=0}
if (unfreeze=1) {frozen=0;unfreeze=0}
if (stop=0) and (insector!=global.player_sector) {
if (frozen=0) {freeze=1}
else {freeze=0}
}
else if (frozen=1) {
unfreeze=1
}
if (freeze=1) {
_vspeed=vspeed
vspeed=0
gravity=0
}
if (unfreeze=1) {
vspeed=_vspeed
gravity=0.1
}
if (vspeed>0) and (collision_rectangle(x-16,y+16,x+15,y+vspeed+16,char,false,true)>0) and (stop=0) {freeze=1;stop=1}
else if (stop=1) {unfreeze=1;stop=0}