Hey guys,
My next programmer's goal is to make a very, very small side-scrolling level. The objective is to have a simple Object called a Bot (rectangle) move using the arrow keys. It can fall and jump. And most importantly, it treats a .GIF as the "world space" where 100% opacity is solid ground, and 0% opacity is open free space. Finally, the level "scrolls" horizontally based on whether or not the Bot.x is lesser than 1/3 width or greater than 2/3 width.
Some pseudocode:
----
-Globals: PImage background, Robot Class. World Class? float friction? float gravity?(ironic)
-Setup: Screensize. load World. load Bot.
-Draw: Draw Everything. Move World based on Bot.x
-keyPressed: Move Bot.
----
-Robot: Contains x,y and w.(PVector?)
---Build a Bot that spawns at leftside of level, with a Width of 15 pixels.
-----Bot should Compare its x,y coordinates against the coordinates of the PImage and Save that location as CurrentLocation. On next frame, currentLocation becomes pastLocation. Compare again. If currentLocation coordinates share the same space as an RGB 100% space, currentLocation is changed back to pastLocation.
-------Bot should move based on keyPressed functions that send values to either x or y.
---------display Bot as a semi-transparent Rectangle.
----
-Worldspace Class.
--world consists of a PImage and a 2D Array.
---World is built with an Image and the 2D Array is equal to the pixel dimensions of the image, with each Array storing the Opacity value of each pixel.
----World should have a function that returns the Opacity value of a given pixel or MULTIPLE pixels.
Here's what little I have so far (but it works):
Code:
//Globals
PImage demobg;
int x = 0;
//Robot bot;
void setup() {
size(400,400);
// bot = new Robot();
//load our image
demobg = loadImage("demo_bg.gif");
}
void draw() {
background(255);
image(demobg, x, 0);
println(x);
}
//Scroll Logic
void keyPressed() {
switch(keyCode) {
case RIGHT:
x -= 5;
if (x < (-demobg.width + width)) {
x = (-demobg.width + width);
}
break;
case LEFT:
x += 5;
if (x > 0) {
x = 0;
}
break;
}
}
and the background:
Any help/pointers or things I should research would be appreciated. I already looked at the Off-Screen Buffer hack but that only helped me for directional keyPresses, really.