Code changing
in
Programming Questions
•
2 years ago
Is there any way to change code during the run of the sketch? My problem is that I need to get change a level for a game. Levels are stored in a class called "Level". So, to bring a new level, say level 1, I go level.level1 And that will spawn the new level. What I want to be able to do is to change the "1" at the end of level.level1 so I can switch levels. Any other code corrections would be nice too, though! Code:
- import fisica.*;
- import toxi.geom.*;
- import toxi.math.*;
- import toxi.geom.mesh2d.*;
- FWorld world;
- FPoly tank, gun;
- Tank player;
- Level level;
- /**
- .setStroke(173, 216, 199);
- .setFill(22, 147, 165);
- */
- float tankX, tankY, tankXvelocity, tankYvelocity = 0;
- void setup() {
- size(1024, 512, P2D);
- background(22, 147, 165);
- Fisica.init(this);
- world = new FWorld();
- world.setEdges();
- world.setEdgesFriction(20);
- stroke(0);
- noFill();
- world.setGrabbable(false);
- player = new Tank(100, height-40);
- winball(40,100,100);
- level = new Level();
- }
- void draw() {
- background(22, 147, 165);
- if ( keyPressed) {
- if ( key == 'd' || key == 'D' ) {
- tank.adjustVelocity(20,0);
- } else if ( key == 'a' || key == 'A' ) {
- tank.adjustVelocity(-20,0);
- }
- }
- world.step();
- world.draw(this);
- }
- class Tank{
- int spawnX, spawnYd;
- void Tank(int xSpawn, int ySpawn) {
- tank = new FPoly();
- tank.setStroke(173, 216, 199);
- tank.setFill(22, 147, 165);
- tank.vertex(xSpawn, ySpawn);
- tank.vertex(xSpawn+20, ySpawn);
- tank.vertex(xSpawn+30, ySpawn+5);
- tank.vertex(xSpawn+25, ySpawn+10);
- tank.vertex(xSpawn, ySpawn+10);
- tank.vertex(xSpawn-5, ySpawn+5);
- tank.vertex(xSpawn-3, ySpawn+2);
- world.add(tank);
- }
- }
- void winball( int sizeOf, int Xball, int Yball);
- FBlob winball = new FBlob();
- winball.setStroke(173, 216, 199);
- winball.setFill(22, 147, 165);
- winball.setAsCircle(Xball,Yball,sizeOf);
- world.add(winball);
- }
1